#include <bits/stdc++.h>
using namespace std;
int main() {
  long long s = 0, n;
  cin >> n;
  vector<int> ar(n);
  for (long long i = 0; i < n; i++) cin >> ar[i];
  for (long long i = 1; i < n; i++) {
    if (ar[i - 1] > ar[i]) {
      s += (ar[i - 1] - ar[i]);
      ar[i] = ar[i - 1];
    }
  }
}
