////////////////////////////////////////////////////////
//Gene Assembly
//DNA序列中最多gene序列
//用贪心法,先以基因头位置对基因排序,再用静态链存储、搜索
#include<iostream>
using namespace std;
#define MAX 1005
long st[MAX][2],output[MAX]; //st作为静态链表,output为输出gene的顺序而设
class Point
{
public:
long x;
long y;
long No;
bool operator<=(Point a) //重载<=为了能在合并排序中使用
{
return (x<=a.x);
}
};
//以下是合并排序
///////////////////////////////////////////////////////////////////
template <class Type>
void Merge(Type c[],Type d[],long l, long m, long r)
{
long p,k=l,i=l,j=m+1;
while(i<=m && j<=r)
if(c[i]<=c[j]) d[k++]=c[i++];
else d[k++]=c[j++];
if(j>r)
for(p=i;p<=m;p++) d[k++]=c[p];
else
for(p=j;p<=r;p++) d[k++]=c[p];
}
template <class Type>
void MergePass(Type x[],Type y[], long s, long n)
{
long i=0,j;
while(i<=n-2*s)
{
Merge(x, y, i, i+s-1,i+2*s-1);
i+=2*s;
}
if(i+s<n) Merge(x, y, i, i+s-1, n-1);
else for(j=i;j<n;j++) y[j]=x[j];
}
template <class Type>
void MergeSort(Type a[],long n)
{
Type *b=new Type [n];
long s=1;
while(s<n)
{
MergePass(a,b,s,n);
s+=s;
MergePass(b,a,s,n);
s+=s;
}
}
///////////////////////////////////////////////////////////////////
int main()
{
long i,j,k,n,state,max;
Point node[MAX];
while(cin>>n && n!=0)
{
node[0].x=0;
node[0].y=0;
node[0].No=0;
k=1;
for(i=1;i<=n;i++)
{
cin>>node[i].x>>node[i].y;
node[i].No=k++; //输入时就先把gene的序号用No记录
}
MergeSort(node,n+1);
//贪心法生成以静态链存储的树
st[0][0]=-1; //st[i][0]记录前一节点
st[0][1]=0; //st[i][1]记录层数
for(i=1;i<=n;i++)
{
max=-1;
for(j=0;j<i;j++)
{
if(node[i].x>node[j].y && max<st[j][1])
{
state=j;
max=st[j][1];
}
}
st[i][0]=state;
st[i][1]=max+1;
}
//找出最大层数的节点位置
max=0;
for(i=1;i<=n;i++)
{
if(st[i][1]>max)
{
max=st[i][1];
state=i;
}
}
//把最大链记录到output中
j=0;
while(state!=0)
{
output[j++]=node[state].No;
state=st[state][0];
}
for(i=j-1;i>=0;i--)
{
cout<<output[i];
if(i!=0)
cout<<" ";
}
cout<<endl;
}
return 0;
}