#include
#include
using namespace std;
bool mycompare(pair<string,int> p1,pair<string,int> p2,int n1)
{
if(p1.second==p2.second)
{
return p1.first<p2.first;
}
return p1.second>p2.second;
}
int main() {
int n1;
cin>>n1;
int n;
cin>>n;
pair<string,int> employee[n+1];
int salary;
string name;
for(int i=0;i<n;i++)
{
cin>>name;
cin>>salary;
employee[i].first=name;
employee[i].second=salary;
}
sort(employee,employee+n,mycompare);
for(int i=0;i<n;i++)
{
if(employee[i].second>=n1)
{
cout<<employee[i].first;
cout<<employee[i].second;
}
}
return 0;
}