#include <bits/stdc++.h>
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];
  }
  for (int i = N - 1; i > 0; i--) {
    c = vec[i];
    d = vec[i - 1];
    while (c > d) {
      d++;
      count++;
    }
  }
  cout << count << endl;
}
