#include
#include
#include
using namespace std;
bool sorts(pair<string,int> p1,pair<string, int> p2)
{
if(p1.second==p2.second)
{
return p1.first<p2.first;
}
return p1.second>p2.second;
}
int main()
{
long long int n,x;
cin>>x>>n;
pair<string,int> emp[10000];
string name;
int salary;
for(int i=0;i<n;i++)
{
cin>>name>>salary;
emp[i].first=name;
emp[i].second=salary;
sort(emp, emp+n, sorts);
}
for(int i=0;i<n;i++)
{
if(emp[i].second>=x)
{
cout<<emp[i].first<<" "<<emp[i].second<<endl;
}
}
return 0;
}