#include <bits/stdc++.h>
using namespace std;
pair<int, int> dp[100010][20];
void RMQ_init(const vector<int> &A) {
  int n = A.size();
  for (int i = 0; i < n; i++) dp[i][0] = make_pair(A[i], i);
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 0; i + (1 << j) - 1 < n; i++) {
      dp[i][j] = max(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
    }
  }
}
pair<int, int> RMQ(int L, int R) {
  int k = 0;
  while ((1 << (k + 1)) <= R - L + 1) k++;
  return max(dp[L][k], dp[R - (1 << k) + 1][k]);
}
long long work(int i, vector<long long> &vals, const vector<int> &a, int n) {
  if (vals[i] >= 0) {
    return vals[i];
  }
  if (a[i] == n - 1) {
    return n - i - 1;
  }
  int idx = RMQ(i + 1, a[i]).second;
  long long ret = work(idx, vals, a, n) + n - i - 1;
  ret -= a[i] - idx;
  return vals[i] = ret;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    a[i]--;
  }
  a[n - 1] = n - 1;
  RMQ_init(a);
  long long res = 0;
  vector<long long> vals(n, -1);
  vals[n - 1] = 0;
  for (int i = 0; i < n - 1; i++) {
    long long val = work(i, vals, a, n);
    res += val;
  }
  cout << res << endl;
  return 0;
}
