#include <bits/stdc++.h>
int main() {
  long long int n, t = 0;
  scanf("%lld", &n);
  long long int a[10000];
  for (long long int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }
  for (long long int i = 0; i < n - 1; ++i) {
    if (a[i] > a[i + 1]) {
      a[i + 1] = a[i + 1] + 1;
      t++;
    }
  }
  printf("%lld\n", t);
}
