#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long a[111111], dp[111111], l[111111];
signed main() {
  long long n = read();
  for (long long i = 1; i <= n; ++i) a[i] = read();
  long long pos = a[n] + 1;
  for (long long i = n; i >= 1; --i) {
    pos--;
    pos = max(pos, a[i] + 1);
    l[i] = pos;
  }
  dp[1] = 1;
  long long ans = 0;
  for (long long i = 2; i <= n; ++i) {
    dp[i] = max(dp[i - 1], max(a[i] + 1, l[i]));
  }
  for (long long i = 1; i <= n; ++i) {
    ans += dp[i] - 1 - a[i];
  }
  cout << ans << endl;
  fclose(stdin);
  fclose(stdout);
  return 0;
}
