#include <bits/stdc++.h>
using namespace std;
vector<int> ganti[600001];
typedef pair<pair<long long,int>,int> node;
struct cmp
{
	bool operator()(const node &a, const node &b)
	{
		if(a.first.first*a.first.second != b.first.first*b.first.second) 	return a.first.first*a.first.second < b.first.first*b.first.second;
		return a.second<b.second;
	}
};


int main()
{
	//ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	int m,n;
	cin>>m>>n;
	priority_queue<node,vector<node>,cmp> q;
	for(int temp=0;temp<n;temp++)
	{
		int k,i;
		cin>>k>>i;
		q.push({{k,i},temp+1});
		//cout<<"masukin "<<k<<" "<<i<<" "<<temp+1<<"\n";
	}
	long long ans=0;
	int temp;
	vector<int> pertamax;
	for(temp=0;temp<6;temp++)
	{
		//if(temp!=0)	cout<<" ";
		//cout<<v[temp].ind;
		node t=q.top();
		q.pop();
		ans+=t.first.first*t.first.second;
		ganti[t.first.second+1].push_back(t.second);
		pertamax.push_back(t.second);
	}
	//cout<<"\n";
	vector<tuple<int,int,int>> sub;
	for(temp=2;temp<=m;temp++)
	{
		while(!ganti[temp].empty())
		{
			while(q.top().first.second + temp > m+1)
			{
				node t=q.top();
				q.pop();
				//cout<<"keluarin "<<t.k<<" "<<t.tahan<<" "<<t.ind<<"\n";
				t.first.second=(m-temp+1);
				q.push(t);
				//cout<<"masukin "<<t.k<<" "<<t.tahan<<" "<<t.ind<<"\n";
			}
			node t=q.top();
			while(t==q.top())
			{
				t=q.top();
				q.pop();
				cout<<"atas "<<q.top().first.first<<" "<<q.top().first.second<<" "<<q.top().second<<"\n";
			}
		}
	}
}