import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int X=sc.nextInt();
int n=sc.nextInt();
ArrayList<Sorts> list=new ArrayList<Sorts>();
for(int i=0;i<n;i++)
{
String s=sc.next();
int k=sc.nextInt();
Sorts p=new Sorts(s,k);
list.add(p);
}
Collections.sort(list,new compareSortGame());
for(int i=list.size()-1;i>=0;i--)
{
if(list.get(i).salary>X)
{
System.out.print(list.get(i).s+" ");
System.out.println(list.get(i).salary);
}
}
}
}
class Sorts
{
String s;
int salary;
Sorts(String s,int salary)
{
this.s=s;
this.salary=salary;
}
}
class compareSortGame implements Comparator
{
public int compare(Sorts s1,Sorts s2)
{
int salaryCompare=s1.salary-s2.salary;
int nameCompare=(-1)*(s1.s.compareTo(s2.s));
if(salaryCompare==0)
{
if(nameCompare==0)
{
return salaryCompare;
}
else
{
return nameCompare;
}
}
else
{
return salaryCompare;
}
}
}