#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
long long dp[N];
long long ret, Prev[N], x[N];
long long u, pos, i, j, n;
int main() {
  cin >> n;
  for (i = 1; i <= n - 1; i++) cin >> x[i];
  Prev[++pos] = -n;
  dp[n] = 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;
}
