#include<iostream>
using namespace std;
struct a{
int id;
struct a *next;
};
int N;
int main(){
cin >> N;
struct a b[1000001];
for(int i = 1; i <= N; i++){
int temp;
cin >> temp;
b[i].id = i;
if(temp == 0){
b[i].next=NULL;
continue;
}
b[i].next=&b[temp];
}
int last;
struct a *head = &b[last];
while(head){
cout << head->id << endl;
head = head->next;
}
return 0;
}