#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1000;
struct node {
  int val;
  int lch, rch;
} ns[maxn * 2];
int sz = 0;
int nw(int v) {
  ns[++sz].val = v;
  ns[sz].lch = ns[sz].rch = 0;
  return sz;
}
int root, a[maxn];
void update(int v) {
  if (a[ns[ns[v].lch].val] > a[ns[ns[v].rch].val])
    ns[v].val = ns[ns[v].lch].val;
  else
    ns[v].val = ns[ns[v].rch].val;
}
int build(int l, int r) {
  if (l == r) return nw(l);
  int ret = nw(0), mid = (l + r) / 2;
  ns[ret].lch = build(l, mid);
  ns[ret].rch = build(mid + 1, r);
  update(ret);
  return ret;
}
int query(int v, int l, int r, int x, int y) {
  if (x <= l && r <= y) return ns[v].val;
  int mid = (l + r) / 2, cur1 = 0, cur2 = 0;
  if (mid >= x) cur1 = query(ns[v].lch, l, mid, x, y);
  if (mid < y) cur2 = query(ns[v].rch, mid + 1, r, x, y);
  if (a[cur1] > a[cur2])
    return cur1;
  else
    return cur2;
}
long long ans[maxn], fans = 0;
int n;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i < n; i++) cin >> a[i];
  ans[n] = 0;
  root = build(1, n);
  for (int i = n - 1; i >= 1; i--) {
    int cur = query(root, 1, n, i + 1, a[i]);
    ans[i] = ans[cur] + n - i - (a[i] - cur);
    fans += ans[i];
  }
  cout << fans << endl;
  return 0;
}
