////////////////////////////////////////////////////////
//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;
}