Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values p_i — the index of the router to which the i-th router was connected after being purchased (p_i < i).

There are n routers in Boogle in total now. Print the sequence of routers on the path from the first to the n-th router.

Input

The first line contains integer number n (2 ≤ n ≤ 200000) — the number of the routers. The following line contains n-1 integers p_2, p_3, ..., p_n (1 ≤ p_i < i), where p_i is equal to index of the router to which the i-th was connected after purchase.

Output

Print the path from the 1-st to the n-th router. It starts with 1 and ends with n. All the elements in the path should be distinct.

Examples

Input

8
1 1 2 2 3 2 5


Output

1 2 5 8 

Input

6
1 2 3 4 5


Output

1 2 3 4 5 6 

Input

7
1 1 2 3 4 3


Output

1 3 7 
import java.util.*;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Solution {
	static BufferedReader br;
	static StringTokenizer sc;
	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		//br = new BufferedReader(new FileReader("input.in"));
		br = new BufferedReader(new InputStreamReader(System.in));
		//out = new PrintWriter("output.out");
		out = new PrintWriter(System.out);
		sc = new StringTokenizer("");

		TaskD solver = new TaskD();
		solver.solve();

		br.close();
		out.close();
		//System.out.println("Finished");
	}    

	static class TaskD {
		public void solve() throws IOException {
			int n = nxtInt();
			int[] p = new int[n - 1];
			for (int i = 0; i < p.length; i++)
				p[i] = nxtInt();

			int[] path = new int[n];			
			path[0] = n;
			int index = 1;

			while (n > 1) {
				n = path[index++] = p[n - 2]; 
			}

			for (int i = index - 1; i > 0; i--) {
				out.print(path[i] + " ");
			}
			out.print(path[0]);
		}

		class Trie {
			Node root;

			Trie() {
				root = new Node();
			}

			void add(long x) {

				Node cur = root;
				// int depth = 0;
				while (x > 0) {
					int ls = (int)(x % 10);
					x /= 10;
					cur.cnt[ls]++;
					if (cur.nodes[ls] == null)
						cur.nodes[ls] = new Node();
					cur = cur.nodes[ls];
				}
			}

			void sub(long x) {

				Node cur = root;
				while (x > 0) {
					int ls = (int)(x % 10);
					x /= 10;
					cur.cnt[ls]--;
					cur = cur.nodes[ls];
				}
			}

			long[] getcnt(long x) {

				int res = 0;
				int prev = 0;
				int depth = 0;
				Node cur = root;

				while (x > 0 && depth < 10) {
					int ls = (int)(x % 10);
					x /= 10;
					res = cur.cnt[9 - ls];
					if (res != 0) {
						depth++;
						prev = res;
						cur = cur.nodes[9 - ls];
					} else
						break;
				}

				return new long[]{depth, prev};
			}

		}

		class Node {
			Node[] nodes;
			int[] cnt;

			Node() {
				nodes = new Node[10];
				cnt = new int[10];
			}

		}

	}

	static String nxtTok() throws IOException {
		while (!sc.hasMoreTokens()) {
			String s = br.readLine();

			if (s == null) {
				return null;
			}
			sc = new StringTokenizer(s.trim());
		}
		return sc.nextToken();
	}

	static int nxtInt() throws IOException {
		return Integer.parseInt(nxtTok());
	}

	static long nxtLng() throws IOException {
		return Long.parseLong(nxtTok());
	}

	static double nxtDbl() throws IOException {
		return Double.parseDouble(nxtTok());
	}

	static int[] nxtIntArr(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nxtInt();
		}
		return a;
	}

	static long[] nxtLngArr(int n) throws IOException {
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = nxtLng();
		}
		return a;
	}

	static char[] nxtCharArr() throws IOException {
		return nxtTok().toCharArray();
	}

	static int getMin(int arr[], int count)
	{
		int min = arr[0];
		for (int i = 1; i < count; i++)
			if (arr[i] < min)
				min = arr[i];

		return min;
	}

	static int getMax(int arr[], int count)
	{
		int max = arr[0];
		for (int i = 1; i < count; i++)
			if (arr[i] > max)
				max = arr[i];

		return max;
	}

	static void sortAsc(int arr[], int count)
	{
		int temp;

		for (int i = 0; i < count - 1; i++)
		{
			for (int j = i + 1; j < count; j++)
			{
				if (arr[i] > arr[j])
				{
					temp = arr[i];
					arr[i] = arr[j];
					arr[j] = temp;
				}
			}
		}
	}

	static void sortDesc(int arr[], int count)
	{
		int temp;

		for (int i = 0; i < count - 1; i++)
		{
			for (int j = i + 1; j < count; j++)
			{
				if (arr[i] < arr[j])
				{
					temp = arr[i];
					arr[i] = arr[j];
					arr[j] = temp;
				}
			}
		}
	}
} 