#include <bits/stdc++.h>
using namespace std;
const int MAXS = 10e4 + 10;
long long wyn = 0;
int n;
long long dp[MAXS];
pair<long long, long long> tab[MAXS][18];
int lg2[MAXS];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int k = 0;
  while ((1 << k) <= n) {
    int p1 = 1 << k;
    int p2 = min((1 << (k + 1)) - 1, n);
    for (int i = p1; i <= (p2); i++) lg2[i] = k;
    k++;
  }
  for (int i = 1; i <= (n - 1); i++) {
    cin >> tab[i][0].first;
    tab[i][0].second = i;
  }
  for (int k = 1; k <= (17); k++)
    for (int i = 1; i <= (n - 1); i++) {
      if (tab[i][k - 1].first >= tab[min(i + (1 << (k - 1)), n)][k - 1].first)
        tab[i][k] = tab[i][k - 1];
      else
        tab[i][k] = tab[min(i + (1 << (k - 1)), n)][k - 1];
    }
  for (int i = n - 1; i >= (1); i--) {
    int par1 = tab[i][0].first;
    if (par1 == n)
      dp[i] = n - i;
    else {
      int l = i + 1;
      int r = par1;
      int lge = lg2[r - l + 1];
      int m_pr = (tab[l][lge].first > tab[r - (1 << lge) + 1][lge].first)
                     ? tab[l][lge].second
                     : tab[r - (1 << lge) + 1][lge].second;
      dp[i] = n - i + dp[m_pr] - (par1 - m_pr);
    }
    wyn += dp[i];
  }
  cout << wyn;
  return 0;
}
