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