#include <stdio.h>
#include <string.h>
char B[200],*p=B;
inline void e(register int &x)
{
for(;*p<‘0‘||*p>‘9‘;p++);
for(x=0;*p>=‘0‘&&*p<=‘9‘;p++)x=(x<<1)+(x<<3)+*p-‘0‘;
}
int n,root,fa[100],ls[100],rs[100],a[100];
inline void solve()
{
register int x=root;
while(~rs[x])x=ls[x];
register int t=ls[x];
if((~t)&&(!~ls[t])&&(!~rs[t]))x=t;
a[++a[0]]=x;
if(x==root)root=ls[root];
register int f=fa[x];
if(~f)ls[f]=ls[x],fa[ls[f]]=f;
while(~f)ls[f]^=rs[f]^=ls[f]^=rs[f],f=fa[f];
}
int main()
{
fa[0]=-1,memset(ls,-1,sizeof ls),memset(rs,-1,sizeof rs),fread(p,1,200,stdin),e(n);
for(register int i=1,x;i<=n;i++)e(x),(x<100)?(fa[i]=x,ls[x]=i):(fa[i]=x-100,rs[x-100]=i);
for(register int i=0;i<=n;i++)solve();
for(;a[0];a[0]--)printf("%d ",a[a[0]]);
return 0;
}