// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int &s = 0, const int &d = 0, const Weight &w = 0) : src(s), dst(d), weight(w) {}
};

using Edges = vector<Edge>;

class Graph {
  vector<Edges> g;
  using iterator = vector<Edges>::iterator;
  using const_iterator = vector<Edges>::const_iterator;

public:
  Graph(const int &size = 0) : g(size) {}
  size_t size() const { return g.size(); }
  const Edges &operator[](const int &i) const { return g[i]; }
  Edges &operator[](const int &i) { return g[i]; }
  void addArc(const int &src, const int &dst, const Weight &w = 1) { g[src].emplace_back(src, dst, w); }
  void addEdge(const int &node1, const int &node2, const Weight &w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }
  iterator begin() { return g.begin(); }
  const_iterator begin() const { return g.begin(); }
  iterator end() { return g.end(); }
  const_iterator end() const { return g.end(); }
};

class LCA {
  int n = 0;
  int log2_n = 0;
  vector<vector<int>> _parent;
  vector<int> _depth;

public:
  LCA() {}

  LCA(const Graph &g, const int &root = 0) : n(g.size()), log2_n(log2(n) + 1), _parent(log2_n, vector<int>(n)), _depth(n) {
    dfs(g, root, -1, 0);
    rep(k, log2_n - 1) rep(v, g.size()) _parent[k + 1][v] = _parent[k][v] < 0 ? -1 : _parent[k][_parent[k][v]];
  }

  void dfs(const Graph &g, const int &v, const int &p, const int &d) {
    _parent[0][v] = p;
    _depth[v] = d;
    for (auto &e : g[v]) {
      if (e.dst != p) dfs(g, e.dst, v, d + e.weight);
    }
  }

  int get(int u, int v) {
    if (_depth[u] > _depth[v]) swap(u, v);
    rep(k, log2_n) if ((_depth[v] - _depth[u]) >> k & 1) v = _parent[k][v];
    if (u == v) return u;
    for (int k = log2_n - 1; k >= 0; k--) {
      if (_parent[k][u] != _parent[k][v]) {
        u = _parent[k][u];
        v = _parent[k][v];
      }
    }
    return _parent[0][u];
  }

  int parent(const int &v) { return _parent[0][v]; }

  int depth(const int &v) { return _depth[v]; }

  int distance(const int &u, const int &v) { return _depth[u] + _depth[v] - 2 * _depth[get(u, v)]; }

  // is b between a and c
  bool onPath(const int &a, const int &b, const int &c) { return distance(a, b) + distance(b, c) == distance(a, c); }

  // neighbor of a between a and b
  int neighborOnPath(int a, int b) {
    if (get(a, b) == a) {
      for (int k = log2_n - 1; k >= 0; k--) {
        if (_parent[k][b] != -1 && _depth[a] < _depth[_parent[k][b]]) b = _parent[k][b];
      }
      return b;
    } else {
      return _parent[0][a];
    }
  }
};

vector<int> bfsOrder(const Graph &g) {
  vector<int> vs;
  vector<int> visited(g.size());
  queue<int> q({0});
  while (q.size()) {
    int v = q.front();
    q.pop();
    if (visited[v]) continue;
    visited[v] = true;
    vs.emplace_back(v);
    for (auto &e : g[v]) q.emplace(e.dst);
  }
  return vs;
}

signed main() {
  int n;
  cin >> n;
  Graph g(n);
  loop(i, 1, n) {
    int p;
    cin >> p;
    --p;
    g.addArc(p, i);
  }
  LCA lca(g, 0);
  int s = 0;
  auto ord = bfsOrder(g);
  loop(i, 1, ord.size()) s += lca.distance(ord[i], ord[i - 1]);
  cout << s << endl;
}



Measured memory_bytes: 28188