#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
template <typename T>
struct SegTree {
  int N;
  T inf;
  vector<T> dat;
  SegTree(int n, T x) {
    N = 1;
    while (N < n) N *= 2;
    inf = x;
    dat = vector<T>(2 * N - 1, inf);
  }
  void update(int i, T x) {
    i += N - 1;
    dat[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }
  T query(int a, int b) { return query(a, b, 0, 0, N); }
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return inf;
    if (a <= l && r <= b) return dat[k];
    int m = (l + r) / 2;
    return max(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
  }
};
long long func() {
  vector<long long> dp(n);
  SegTree<pair<int, int>> seg(n, make_pair(-1, -1));
  for (int i = 0; i < n; ++i) {
    seg.update(i, make_pair(a[i], i));
  }
  for (int i = n - 2; i >= 0; --i) {
    int m = seg.query(i + 1, a[i] + 1).second;
    dp[i] = dp[m] - (a[i] - m) + n - i - 1;
  }
  long long r = 0;
  for (int i = 0; i < n; ++i) r += dp[i];
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a.resize(n - 1);
  for (int& x : a) {
    cin >> x;
    --x;
  }
  a.push_back(n - 1);
  cout << func() << endl;
}
