#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("/home/krishna/Documents/competitive/input.txt", "r", stdin);
	freopen("/home/krishna/Documents/competitive/output.txt", "w", stdout);
#endif
}
bool mycomp(pair<int,string> p1,pair<int,string> p2)
{
	if(p1.first>p2.first)
		return true;
	else if(p1.first<p2.first)
		return false;
	else
	{
		if(p1.second<p2.second)
			return true;
		else
			return false;
	}
}

int32_t main()
{
	c_p_c();
	int x,n;
	cin>>x;
	cin>>n;
	int salary,cnt=0;
	string name;
	vector<pair<int,string>> payroll;
	payroll.reserve(n);
	for(int i=0;i<n;i++)
	{
		cin>>name>>salary;
		if(salary>=x)
		{
		payroll.push_back(mp(salary,name));
		cnt++;
		}

	}
	sort(payroll.begin(),payroll.end(),mycomp);
	for(auto i: payroll)
		cout<<i.first<<" "<<i.second<<endl;

	return 0;
}