#include <bits/stdc++.h>
using namespace std;
long long n, m[100011], dp[100011];
long long l[100011];
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &m[i]);
  long long now;
  now = m[n] + 1;
  for (int i = n; i >= 1; i--) {
    now--;
    now = max(now, m[i] + 1);
    l[i] = now;
  }
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = dp[i - 1];
    dp[i] = max(dp[i], m[i] + 1);
    dp[i] = max(dp[i], l[i]);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += dp[i] - 1 - m[i];
  printf("%lld\n", ans);
}
