#include <iostream>
#include <vector>
using namespace std;

int main() {
  	int N, c, d;
  	int count = 0;
  	cin >> N;
    vector<int> vec(N);
  	for (int i = 0; i < N; i++) {
          cin >> vec[i];
    }
    max = vec[0];
  	for (int i = 0; i < N-1 ; i++) {
      	c = vec[i];
        d = vec[i+1];
		while (c > d) {
          	d++;
          	count++;
        }
        vec[i+1] = d;
        
    }
    cout << count << endl;
}