@abhay_091
import java.util.Comparator;
import java.util.*;
class Checker implements Comparator {
@Override
public int compare(Employee a, Employee b)
{
// If 2 Players have the same score
if(a.score == b.score){
// Order alphabetically by name
if(a.name.compareTo(b.name) < 0){
return -1;
}
else if(a.name.compareTo(b.name) > 0){
return 1;
}
return 0;
}
// Otherwise, order higher score first
else if(a.score > b.score){
return -1;
}
else if(a.score < b.score){
return 1;
}
return 0;
}
}
class Employee {
String name;
int score;
public Employee(String name, int score)
{
this.name = name;
this.score = score;
}
}
public class Main{
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int x;
x=sc.nextInt();
int n;
n=sc.nextInt();
Employee[] employee=new Employee[n];
Checker checker = new Checker();
for(int i = 0; i < n; i++)
{
employee[i] = new Employee(sc.next(), sc.nextInt());
}
sc.close();
Arrays.sort(employee, checker);
for(int i = 0; i < employee.length; i++){
if(employee[i].score>=x){
System.out.printf("%s %s\n", employee[i].name, employee[i].score);
}
}
}
}