#include <bits/stdc++.h>
using namespace std;
int n;
int A[100005];
long long int dp[100005];
pair<int, int> pos[100005];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &A[i]);
    A[i]--;
  }
  int e = 0;
  long long int ret = 0;
  for (int i = n - 2; i >= 0; i--) {
    while (0 < e && pos[e - 1].second <= A[i]) e--;
    if (e == 0)
      dp[i] = 0;
    else {
      int to = lower_bound(pos, pos + e, pair<int, int>(-A[i], -1)) - pos;
      int v = -pos[to].first;
      dp[i] = dp[v] + v - A[i];
    }
    dp[i] += n - i - 1;
    ret += dp[i];
    pos[e++] = pair<int, int>(-i, A[i]);
  }
  printf("%lld\n", ret);
  return 0;
}
