#include <bits/stdc++.h>
int main() {
  int n, x[200001], i, b, c = 0;
  scanf("%d", &n);
  x[0] = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x[i]);
    if (x[i - 1] >= x[i]) {
      b = x[i - 1] - x[i] + 1;
      x[i] = x[i - 1] + 1;
      if (c < b) c = b;
    }
  }
  printf("%d\n", c);
  return 0;
}
