#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, a[100], fumi = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int m = 1; m < n; m++) {
    for (int s = 0; s < 10; s++) {
      if (a[m - 1] > a[m]) {
        a[m] = a[m] + 1;
        fumi = fumi + 1;
      }
    }
  }
  cout << fumi;
  return 0;
}
