#include <bits/stdc++.h>
using namespace std;
int n, a[100002], aib[100002];
long long dp[100002], ans;
void upd(int x, int y) {
  int i;
  for (i = x; i <= n; i += (i & (-i)))
    if ((dp[aib[i]] > dp[y]) || (dp[y] == dp[aib[i]] && x < aib[i])) aib[i] = x;
}
int query(int z, int x) {
  int i, y = 0;
  for (i = x; i >= z; i -= (i & (-i)))
    if (dp[aib[i]] <= dp[y]) y = aib[i];
  return y;
}
void read() {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
}
void solve() {
  int i;
  dp[0] = 200000000000000000LL;
  dp[n] = n;
  upd(n, n);
  for (i = n - 1; i >= 1; --i) {
    int j = query(i + 1, a[i]);
    dp[i] = i + 1LL * dp[j] + 1LL * (n - i) - 1LL * a[i];
    ans = ans + 1LL * dp[i] - i;
    upd(i, i);
  }
}
void write() { printf("%lld\n", ans); }
int main() {
  read();
  solve();
  write();
  return 0;
}
