#include <bits/stdc++.h>
using namespace std;
int n, a[100001], jg[400001], l[400001], r[400001], b[400001];
unsigned long long ans, g[100001];
int build(int xl, int xr, int cnt) {
  l[cnt] = xl;
  r[cnt] = xr;
  if (xl == xr) {
    jg[cnt] = a[xl];
    b[cnt] = xl;
    return jg[cnt];
  }
  int mid = (xl + xr) / 2;
  int ls = build(xl, mid, cnt << 1), rs = build(mid + 1, xr, cnt << 1 | 1);
  if (ls > rs) {
    b[cnt] = b[cnt << 1];
    jg[cnt] = ls;
  } else {
    b[cnt] = b[cnt << 1 | 1];
    jg[cnt] = rs;
  }
  return jg[cnt];
}
int q(int xl, int xr, int id) {
  if (xl > r[id] || xr < l[id]) return 0;
  if (xl <= l[id] && r[id] <= xr) {
    return b[id];
  }
  int ls = q(xl, xr, id << 1), rs = q(xl, xr, id << 1 | 1);
  if (a[ls] > a[rs]) {
    return ls;
  }
  return rs;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n - 1; i++) cin >> a[i];
  a[0] = 0;
  a[n] = n;
  build(1, n, 1);
  for (int i = n - 1; i >= 1; i--) {
    int x = q(i + 1, a[i], 1);
    g[i] = g[x] + n - x - (a[i] - x) * 2 + a[i] - i;
    ans += g[i];
  }
  cout << ans << endl;
  return 0;
}
