#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long tmp = a[0];
  long long ans = 0;
  for (int i = 1; i < N; i++) {
    ans += max((long long)0, tmp - a[i]);
    tmp = max(tmp, a[i]);
  }
}
