#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> ST[1 << 18];
long long dp[1 << 18], a[1 << 18];
long long n;
void build() {
  for (long long i = n - 1; i >= 0; i--)
    ST[i] = max(ST[i << 1], ST[(i << 1) | 1]);
}
long long query(long long l, long long r) {
  pair<long long, long long> res = {-1, -1};
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = max(res, ST[l++]);
    if (r & 1) res = max(res, ST[--r]);
  }
  return res.second;
}
int main() {
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    cin >> a[i];
    a[i]--;
    ST[i + n].first = a[i];
    ST[i + n].second = i;
  }
  a[n - 1] = n - 1;
  ST[n + n - 1] = {n - 1, n - 1};
  build();
  long long total = 0;
  dp[n - 1] = 0;
  for (long long i = n - 2; i >= 0; i--) {
    long long m = query(i + 1, a[i] + 1);
    dp[i] = dp[m] - (a[i] - m) + n - i - 1;
    total += dp[i];
  }
  cout << total << endl;
}
