#include <bits/stdc++.h>
using namespace std;
int main() {
  int mx = 0, n, an = 0;
  cin >> n;
  vector<int> ls(n);
  for (int &x : ls) cin >> x;
  for (int u = 0; u < n; u++) {
    mx = max(mx, ls[u]);
    an += (mx - ls[u]);
  }
  cout << an << "\n";
}
