#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 6;
const int INF = 0x3f3f3f3f;
struct Segtree {
  int l, r;
  pair<int, int> e;
  int mid() { return l + (r - l) / 2; }
} tree[MAXN << 2];
int n, a[MAXN];
long long dp[MAXN];
void pushup(int o) {
  tree[o].e =
      (tree[o << 1].e.second >= tree[o << 1 | 1].e.second ? tree[o << 1].e
                                                          : tree[o << 1 | 1].e);
}
void build(int l, int r, int o) {
  tree[o].l = l, tree[o].r = r;
  if (l == r) {
    if (l == n)
      a[l] = tree[o].e.second = n;
    else
      scanf("%d", &tree[o].e.second), a[l] = tree[o].e.second;
    tree[o].e.first = l;
    return;
  }
  int m = tree[o].mid();
  build(l, m, o << 1);
  build(m + 1, r, o << 1 | 1);
  pushup(o);
}
int query(int l, int r, int o) {
  if (tree[o].l == l && tree[o].r == r) return tree[o].e.first;
  int m = tree[o].mid();
  if (l > m)
    return query(l, r, o << 1 | 1);
  else if (r <= m)
    return query(l, r, o << 1);
  else {
    int pos1 = query(l, m, o << 1), pos2 = query(m + 1, r, o << 1 | 1);
    if (a[pos1] >= a[pos2])
      return pos1;
    else
      return pos2;
  }
}
int main() {
  scanf("%d", &n);
  build(1, n, 1);
  long long ans = 0;
  for (int i = n - 1; i >= 1; i--) {
    int pos = query(i + 1, a[i], 1);
    dp[i] = dp[pos] + n - i - (a[i] - pos);
    ans += dp[i];
  }
  printf("%I64d\n", ans);
  return 0;
}
