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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.AbstractList;
import java.io.IOException;
import java.util.stream.Collectors;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author luckman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Contest1057_A solver = new Contest1057_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class Contest1057_A {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            List<Integer> parents = new ArrayList<>();
            for (int i = 0; i < n - 1; i++) {
                parents.add(in.nextInt());
            }

            AdjacencyListUndirectedGraph graph = new AdjacencyListUndirectedGraph(n);

            for (int i = 0; i < parents.size(); i++) {
                graph.putEdge(i + 1, parents.get(i) - 1);
            }
            List<Integer> order = DfsBased.get().dfsFromSingleVertex(graph, n - 1);
            List<Integer> result = new ArrayListInt();
            for (int i = 0; i < order.size(); i++) {
                result.add(order.get(i) + 1);
                if (order.get(i) == 0) {
                    break;
                }
            }
            Collections.reverse(result);
            out.println(result.stream().map(String::valueOf).collect(Collectors.joining(" ")));
        }

    }

    static abstract class AbstractGraphIntNodes<T extends Collection<Integer>> extends AbstractBaseGraph<Integer> implements BaseGraph<Integer>, Undirected<Integer>, AdjacencyListCustomNodes<Integer, T> {
        protected int nodeCount;

        public int getNodeCount() {
            return nodeCount;
        }

    }

    static class DfsBased {
        private boolean[] visited = null;
        private ArrayListInt dfsResultOrder = null;
        private AbstractGraphIntNodes<? extends Collection<Integer>> graphIntNodes;

        private DfsBased() {

        }

        public static DfsBased get() {
            return new DfsBased();
        }

        public List<Integer> dfsFromSingleVertex(AbstractGraphIntNodes<? extends Collection<Integer>> graphIntNodes, Integer from) {
            this.graphIntNodes = graphIntNodes;
            if (visited == null) {
                visited = new boolean[graphIntNodes.getNodeCount()];
            }
            if (dfsResultOrder == null) {
                dfsResultOrder = new ArrayListInt();
            }
            doDfsIntNodes(from);
            return dfsResultOrder;
        }

        private void doDfsIntNodes(Integer vertex) {
            dfsResultOrder.add(vertex);
            visited[vertex] = true;
            for (Integer adj : graphIntNodes.adjacentNodes(vertex)) {
                if (!visited[adj]) {
                    doDfsIntNodes(adj);
                }
            }
        }

    }

    static abstract class AbstractBaseGraph<N> implements BaseGraph<N> {
        protected abstract boolean putEdgeValidated(N nodeU, N nodeV);

        public boolean putEdge(N nodeU, N nodeV) {
            validateNodeNotNull(nodeU);
            validateNodeNotNull(nodeV);
            return putEdgeValidated(nodeU, nodeV);
        }

        protected void validateNodeNotNull(N node) {
            if (node == null) {
                throw new NullPointerException();
            }
        }

    }

    static interface Undirected<N> extends BaseGraph<N> {
    }

    static interface AdjacencyListCustomNodes<N, T extends Collection<N>> extends BaseGraph<N> {
        T adjacentNodes(N node);

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public InputReader(FileReader fr) {
            reader = new BufferedReader(fr);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class AdjacencyListUndirectedGraph extends AbstractGraphIntNodes<ArrayListInt> implements Undirected<Integer> {
        private ArrayListInt[] adjacent;

        public AdjacencyListUndirectedGraph(int nodeCount) {
            adjacent = new ArrayListInt[nodeCount];
            for (int i = 0; i < nodeCount; i++) {
                adjacent[i] = new ArrayListInt();
            }
            this.nodeCount = nodeCount;
        }

        protected boolean putEdgeValidated(Integer nodeU, Integer nodeV) {
            adjacent[nodeU].add(nodeV);
            adjacent[nodeV].add(nodeU);
            return true;
        }

        public ArrayListInt adjacentNodes(Integer node) {
            validateNodeNotNull(node);
            return adjacent[node];
        }

    }

    static interface BaseGraph<N> {
    }

    static class ArrayListInt extends AbstractList<Integer> {
        private int size;
        private int[] data;

        public ArrayListInt() {
            data = new int[3];
        }

        public ArrayListInt(int capacity) {
            data = new int[capacity];
        }

        public int size() {
            return size;
        }

        public boolean isEmpty() {
            return size == 0;
        }

        public boolean add(Integer element) {
            checkNotNull(element);
            ensureCapacity(size + 1);
            data[size] = element;
            size++;
            return true;
        }

        public Integer get(int index) {
            validateIndexBoundsGetSet(index);
            return data[index];
        }

        public Integer set(int index, Integer element) {
            checkNotNull(element);
            validateIndexBoundsGetSet(index);
            int old = data[index];
            data[index] = element;
            return old;
        }

        public void add(int index, Integer element) {
            checkNotNull(element);
            validateIndexBoundsAddDelete(index);
            ensureCapacity(size + 1);

            if (index != size) {
                System.arraycopy(data, index, data, index + 1, size - index);
            }
            data[index] = element;
            size++;
        }

        public Integer remove(int index) {
            validateIndexBoundsAddDelete(index);
            int old = data[index];
            if (index != size - 1) {
                System.arraycopy(data, index + 1, data, index, size - index - 1);
            }
            size--;
            return old;
        }

        public void clear() {
            size = 0;
        }

        public int indexOf(Object o) {
            int intValue = (int) o;
            for (int i = 0; i < size; i++) {
                if (data[i] == intValue) {
                    return i;
                }
            }
            return -1;
        }

        public int lastIndexOf(Object o) {
            int intValue = (int) o;
            for (int i = size - 1; i >= 0; i--) {
                if (data[i] == intValue) {
                    return i;
                }
            }
            return -1;
        }

        public boolean addAll(Collection<? extends Integer> c) {
            ensureCapacity(size + c.size());
            for (Integer elem : c) {
                add(elem);
            }
            return !c.isEmpty();
        }

        private void checkNotNull(Integer element) {
            if (element == null) {
                throw new NullPointerException();
            }
        }

        private void validateIndexBoundsGetSet(int index) {
            if (index >= size || index < 0) {
                throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
            }
        }

        private void validateIndexBoundsAddDelete(int index) {
            if (index > size || index < 0) {
                throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
            }
        }

        private void ensureCapacity(int capacity) {
            if (data.length >= capacity) {
                return;
            }
            capacity = Math.max(2 * data.length, capacity);
            data = Arrays.copyOf(data, capacity);
        }

    }
}

