#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, i, a;
  cin >> N;
  int A[N];
  for (i = 0; i < N; i++) cin >> A[i];
  a = 0;
  for (i = 1; i < N; i++) {
    while (A[i - 1] > A[i]) {
      A[i]++;
      a++;
    }
  }
  cout << a << endl;
}
