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