#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
int a[MAXN + 1];
pair<int, int> tMax[4 * MAXN + 1];
long long dp[MAXN + 1];
void build(int v = 1, int l = 1, int r = MAXN) {
  if (l == r)
    tMax[v] = {a[l], l}, dp[l] = 1e18;
  else {
    int m = (l + r) / 2;
    build(v * 2, l, m);
    build(v * 2 + 1, m + 1, r);
    tMax[v] = max(tMax[v * 2], tMax[v * 2 + 1]);
  }
}
pair<int, int> getMax(int l, int r, int tv = 1, int tl = 1, int tr = MAXN) {
  if (l > r)
    return {0, 0};
  else if (l == tl && r == tr)
    return tMax[tv];
  else {
    int tm = (tl + tr) / 2;
    return max(getMax(l, min(tm, r), tv * 2, tl, tm),
               getMax(max(tm + 1, l), r, tv * 2 + 1, tm + 1, tr));
  }
}
signed main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build();
  dp[n] = 0;
  for (int i = n - 1; i >= 1; i--) {
    int x = getMax(i + 1, a[i]).second;
    dp[i] = dp[x] - (a[i] - x) + (n - i);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += dp[i];
  cout << ans << endl;
  return 0;
}
