#include <bits/stdc++.h>
using namespace std;
int n;
int a[100001];
int loga[100001];
long long dp[100001];
int main() {
  if (!(scanf("%d", &n))) {
    printf("CHECK(%s) failed\n", "scanf(\"%d\", &n)");
    exit(0);
  };
  a[0] = 0;
  for (int i = 1; i < n; ++i) {
    if (!(scanf("%d", &a[i]))) {
      printf("CHECK(%s) failed\n", "scanf(\"%d\", &a[i])");
      exit(0);
    };
  }
  a[n] = n;
  loga[n] = n;
  dp[n] = 0;
  long long ret = 0;
  for (int i = n - 1; i > 0; --i) {
    int x = i + 1;
    for (int j = a[i]; j > 0; j -= j & -j) {
      if (a[loga[j]] > a[x]) x = loga[j];
    }
    for (int j = i; j <= n; j += j & -j) {
      if (a[i] > a[loga[j]]) loga[j] = i;
    }
    dp[i] = dp[x] + n - i - (a[i] - x);
    ret += dp[i];
  }
  printf("%lld\n", ret);
  return 0;
}
