#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::stack<int> path;
  std::stack<int> routers;
  int k;
  for (int i = 0; i < n - 1; i++) {
    std::cin >> k;
    routers.push(k);
  }
  int router = n;
  int to_go = k;
  while (to_go != 1) {
    for (int i = 0; i < (router - to_go); i++) {
      routers.pop();
    }
    router = to_go;
    to_go = routers.top();
    path.push(router);
  }
  std::cout << 1 << " ";
  int r;
  while (!path.empty()) {
    r = path.top();
    path.pop();
    std::cout << r << " ";
  }
  std::cout << n << " ";
}
