/*
最近老是犯一些超级低级的错误
比如说看错题。。。
注意output里的这一句
"The i-th integer indicates the room number of the i-th renter"
这就暗示要对renter进行排序
如果你把实例中的renter顺序打乱后
输出的结果也是相应的打乱的结果
那估计就能AC了
*/
#define LOCAL
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<string>
#include<algorithm>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
class ROOM
{public:int come,leave;};
class RENTER
{public:int num,come,leave;};
bool cmp(const RENTER &a,const RENTER &b)
{if(a.come<b.come) return true;else return false;}
int main()
{
#ifdef LOCAL
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int nrenter,nroom,a,b,i,j,full,find,k,ans[105];
ROOM room[105];RENTER renter[105];
while(cin>>nrenter>>nroom,nrenter)
{
for(i=0;i<nrenter;i++)//读入renter
{cin>>renter[i].come>>renter[i].leave;renter[i].num=i;}//记录编号
sort(renter,renter+nrenter,cmp);//根据到来的日期进行排序
room[0].come=renter[0].come; //第一位renter入住
room[0].leave=renter[0].leave;
full=1; //full记录的是已经有人入住的房间数
ans[renter[0].num]=1; //记录第一位renter的房间号
for(i=1;i<nrenter;i++)//对以后的各个renter进行房间分配
{
find=0;//记录能不能在已经有人入住的房间里找到可住房
for(j=0;j<full;j++)//对有人入住的各个房间进行遍历
{
if(renter[i].come>=room[j].leave)//可住
{
room[j].come=renter[i].come;
room[j].leave=renter[i].leave;
ans[renter[i].num]=j+1;
find=1;
break;
}
}
if(!find)//没有在有人入住的房间里找到可住房
{
if(full<nroom)//如果还有空余房间就分配
{
room[full].come=renter[i].come;
room[full].leave=renter[i].leave;
full++;
ans[renter[i].num]=full;
}
else//否则无法入住
ans[renter[i].num]=0;
}
}
for(i=0;i<nrenter;i++)//输出结果
cout<<ans[i]<<endl;
}
return 0;
}