#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int dp[N];
  long long total = 0;
  dp[0] = 0;
  for (int i = 0; i < N - 1; i++) {
    dp[i + 1] = 0;
    for (int j = 0; j < 10000000; j++) {
      dp[i + 1] = j;
      if ((A[i] + dp[i]) <= (A[i + 1] + dp[i + 1])) {
        break;
      }
    }
    total = total + dp[i + 1];
  }
  cout << total << endl;
}
