#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const long long N = 1e5 + 5, L = 22;
long long n, dp[N], a[N], ans;
long long p[N];
pair<long long, long long> sparse[L][N];
void calc() {
  p[0] = p[1] = 0;
  for (long long i = 2; i < N; i++) p[i] = 1 + p[i / 2];
  for (long long i = 0; i < n; i++)
    sparse[0][i].first = a[i], sparse[0][i].second = i;
  for (long long k = 1; k < L; k++) {
    for (long long i = 0; i + (1 << k) <= n; i++) {
      if (sparse[k - 1][i].first > sparse[k - 1][i + (1 << (k - 1))].first)
        sparse[k][i] = sparse[k - 1][i];
      else
        sparse[k][i] = sparse[k - 1][i + (1 << (k - 1))];
    }
  }
}
long long query(long long l, long long r) {
  long long k = p[r - l + 1];
  if (sparse[k][l].first > sparse[k][r - (1 << k) + 1].first)
    return sparse[k][l].second;
  else
    return sparse[k][r - (1 << k) + 1].second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long i = 0; i < n - 1; i++) cin >> a[i], a[i]--;
  a[n - 1] = n - 1;
  calc();
  for (long long i = n - 2; i >= 0; i--)
    dp[i] = dp[query(i + 1, a[i])] + (n - 1 - i) - (a[i] - query(i + 1, a[i]));
  cout << accumulate(dp, dp + n, 0ll);
}
