#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int sum = 0;
  for (int i = 0; i < (N); i++) cin >> a[i];
  for (int i = 0; i < (N); i++) {
    int ma = -100;
    ma = max(ma, a[i]);
    if (ma != a[i]) sum = sum + (ma - a[i]);
  }
  cout << sum << endl;
  return 0;
}
