#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int m[N], t[N], n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &m[i]);
  }
  long long sum = 0;
  int mx = 0;
  for (int i = n; i > 0; i--) {
    t[i] = max(t[i + 1] - 1, m[i] + 1);
  }
  for (int i = 1; i <= n; i++) {
    mx = max(t[i], mx);
    sum += mx;
  }
  for (int i = 1; i <= n; i++) sum -= m[i] + 1;
  printf("%lld\n", sum);
  return 0;
}
