#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ar[200000], i, j;
  int c = 0, mx = 0, mn = 1000000000;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
    mx = max(ar[i], mx);
    mn = min(ar[i], mn);
  }
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (ar[i] > ar[j]) c = c + ar[i] - ar[j];
    }
    if (ar[i] == mx) break;
  }
  cout << c << endl;
}
