#include
#include
#include
using namespace std;
bool compare(pair<string,int> p1,pair<string,int> p2){
if(p1.second == p2.second){
return p1.first < p2.first;
}else{
return p1.second > p2.second;
}
}
int main(){
int Max;
cin>>Max;
int n;
cin>>n;
vector<pair<string,int>> p;
for(int i=0;i<n;i++){
string x;
int y;
cin>>x>>y;
p.push_back(make_pair(x,y));
}
sort(p.begin(),p.end(),compare);
for(auto v:p){
if( (v.second >= 1) && (v.second <=100)){
if(v.second > Max){
cout<<v.first<<" "<<v.second<<endl;
}
}
}
}
//where is the error in code