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