#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long int m[n + 1], t[n + 1], sm = 0, st = 0;
  t[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> m[i];
    t[i] = max(m[i] + 1, t[i - 1]);
  }
  for (int i = n - 1; i > 0; i--) {
    if (t[i] < (t[i + 1] - 1)) {
      t[i] = t[i + 1] - 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    sm += m[i] + 1;
    st += t[i];
  }
  cout << (st - sm);
}
