import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int a = scn.nextInt();
class employee{
String name;
int salary;
}
employee[] emp = new employee[a];
for(int i=0; i<a; i++){
emp[i].name = scn.nextLine();
emp[i].salary = scn.nextInt();
scn.nextLine();
}
for(int i=0; i<a-1; i++){
for(int j=0; j<a-i-1; j++){
if(emp[j].salary<emp[j+1].salary){
employee temp = emp[j];
emp[j]=emp[j+1];
emp[j+1]=temp;
}
if(emp[j]==emp[j+1] && emp[j].name.compareTo(emp[j+1].name)<0){
employee temp = emp[j];
emp[j]=emp[j+1];
emp[j+1]=temp;
}
}
}
for(int i=0; i<a; i++){
if(emp[i].salary<n)
break;
System.out.println(emp[i].name + " " + emp[i].salary);
}
}
}