class Employee {
String name;
int salary;
Employee(String name, int salary) {
this.name = name;
this.salary = salary;
}
public String toString() {
return name + " " + salary;
}
}
public class App03_SortGame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// System.out.println("Enter max salary");
int maxsal = sc.nextInt();
// System.out.println("Enter no of employee");
ArrayList<Employee> l = new ArrayList<Employee>();
int nemp = sc.nextInt();
while (nemp != 0) {
// System.out.println("Enter name for employee " + nemp);
String name = sc.next();
// System.out.println("Enter salary for employee " + nemp);
int salary = sc.nextInt();
l.add(new Employee(name, salary));
nemp--;
}
System.out.println();
Collections.sort(l, (e1, e2) -> (e1.salary > e2.salary) ? -1 : (e1.salary < e2.salary) ? 1 : 0);
for (int i = 0; i < l.size() - 1; i++) {
if (l.get(i).name.compareTo(l.get(i + 1).name) > 0) {
String tempname = l.get(i).name;
int tempsal = l.get(i).salary;
l.get(i).name = l.get(i + 1).name;
l.get(i).salary = l.get(i + 1).salary;
l.get(i + 1).name = tempname;
l.get(i + 1).salary = tempsal;
}
}
for (Employee employee : l) {
if (employee.salary > maxsal)
System.out.println(employee);
}
}
}