#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long ans = 0, dp[n], m;
  cin >> m;
  dp[0] = 1;
  vector<int> used;
  for (int i = 1; i < n; i++) {
    cin >> m;
    used.push_back(i);
    if (m < dp[i - 1]) {
      dp[i] = dp[i - 1];
      ans += dp[i] - m - 1;
      continue;
    }
    for (int j = 0; j <= m - dp[i - 1]; j++) {
      long long t = used[used.size() - 1];
      used.pop_back();
      ans += i - t;
    }
    dp[i] = m + 1;
  }
  cout << ans << "\n";
  return 0;
}
