#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
int n, a[maxN];
long long dp[maxN];
vector<int> vec;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d", a + i - 1);
    a[i - 1]--;
  }
  vec.push_back(n - 1);
  long long sum = 0;
  for (int i = n - 2; i > -1; i--) {
    int lt = -1;
    int rt = (int)vec.size() - 1;
    while (rt - lt > 1) {
      int md = (lt + rt) / 2;
      (vec[md] <= a[i] ? rt : lt) = md;
    }
    int mx = vec[rt];
    dp[i] = dp[mx] - (a[i] - mx) + n - i - 1;
    while (!vec.empty() && a[vec.back()] <= a[i]) vec.pop_back();
    vec.push_back(i);
    sum += dp[i];
  }
  printf("%lld", sum);
  return 0;
}
