#include <bits/stdc++.h>
using namespace std;
void print() { cout << endl; }
template <typename First, typename... Strings>
void print(First arg, const Strings &...rest) {
  cout << arg << " ";
  print(rest...);
}
template <typename T>
void print(vector<T> &v) {
  for (T x : v) cout << x << " ";
  cout << endl;
}
class sparseTable {
 public:
  long long int n, maxN, L;
  vector<vector<pair<long long int, long long int>>> table;
  sparseTable(long long int _n, long long int l) : maxN(_n), L(l) {
    table.resize(L + 1, vector<pair<long long int, long long int>>(maxN));
  }
  void assign(vector<pair<long long int, long long int>> &data) {
    n = data.size();
    for (int i = 0; i < n; i++) table[0][i] = data[i];
    for (int i = 1; i <= L; i++)
      for (int j = 0; j < n - (1 << i) + 1; j++)
        table[i][j] = max(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]);
  }
  pair<long long int, long long int> queryOverlap(int l, int r) {
    long long int h = floor(log2(r - l + 1));
    return max(table[h][l], table[h][r - (1 << h) + 1]);
  }
};
sparseTable ST(100010, 20);
void test_case() {
  long long int n;
  cin >> n;
  vector<long long int> v(n, 0), dp(n, 0);
  for (long long int i = 0; i < n - 1; i++) cin >> v[i];
  vector<pair<long long int, long long int>> data;
  for (long long int i = 0; i < n; i++) {
    v[i]--;
    data.push_back({v[i], i});
  }
  ST.assign(data);
  long long int res = 0;
  for (long long int i = n - 1 - 1; i >= 0; i--) {
    long long int l = i + 1;
    long long int r = v[i];
    pair<long long int, long long int> pr = ST.queryOverlap(l, r);
    dp[i] = n - i - 1 + dp[pr.second] - (r - pr.second);
    res += dp[i];
  }
  print(res);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    test_case();
  }
  return 0;
}
