#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long dp[N];
int Prev[N], x[N];
int main() {
  int u, pos = 0, i, j, n;
  cin >> n;
  for (i = 1; i <= n - 1; ++i) scanf("%d", &x[i]);
  Prev[++pos] = -n;
  dp[n] = 0;
  long long ret = 0;
  for (i = n - 1; i >= 1; --i) {
    u = lower_bound(Prev + 1, Prev + 1 + pos, -x[i]) - Prev;
    u = -Prev[u];
    dp[i] = dp[u] - (x[i] - u) + n - i;
    ret += dp[i];
    while (pos > 0 && x[-Prev[pos]] <= x[i]) --pos;
    Prev[++pos] = -i;
  }
  cout << ret << endl;
}
