#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, v[N];
long long s, dp[N], rmq[N][20], j, p;
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) scanf("%d", v + i), rmq[i][0] = i;
  rmq[n][0] = n;
  for (j = 1; j < 20; ++j)
    for (int i = 1; i + (1 << j) - 1 <= n; ++i)
      rmq[i][j] = v[rmq[i][j - 1]] > v[rmq[i + (1 << j - 1)][j - 1]]
                      ? rmq[i][j - 1]
                      : rmq[i + (1 << j - 1)][j - 1];
  for (int i = n - 1; i > 0; --i) {
    p = 8 * sizeof(int) - __builtin_clz(v[i] - i) - 1;
    j = v[rmq[i + 1][p]] > v[rmq[v[i] - (1 << p) + 1][p]]
            ? rmq[i + 1][p]
            : rmq[v[i] - (1 << p) + 1][p];
    dp[i] = dp[j] + j - i + n - v[i];
    s += dp[i];
  }
  printf("%lld\n", s);
  return 0;
}
