#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 1;
int N;
int a[maxN], BIT[maxN];
long long f[maxN];
void UpDate(int i, int v) {
  int tmp = i;
  while (i <= N) {
    if (a[BIT[i]] <= v) {
      BIT[i] = tmp;
    }
    i += (i & (-i));
  }
}
int Query(int i) {
  int result = 0;
  while (i) {
    if (a[BIT[i]] > a[result]) result = BIT[i];
    i = i & (i - 1);
  }
  return result;
}
void enter() {
  cin >> N;
  for (int i = 1; i < N; i++) cin >> a[i];
}
void process() {
  a[N] = N;
  UpDate(N, a[N]);
  f[N - 1] = 0;
  for (int i = N - 1; i > 0; i--) {
    int m = Query(a[i]);
    f[i] = f[m] - (a[i] - m) + N - i;
    UpDate(i, a[i]);
  }
  long long res = 0;
  for (int i = N - 1; i > 0; i--) {
    res += f[i];
  }
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  enter();
  process();
  return 0;
}
