#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  long long int a[n];
  for (int i = 0; i < n; i++) {
    long long int aux;
    cin >> aux;
    a[i] = aux;
  }
  int max_idx = 0;
  long long int max = a[max_idx];
  for (int i = 1; i < n; i++) {
    if (a[i] > max) {
      max_idx = i;
      max = a[i];
    }
  }
  long long int s = 0;
  for (int i = 0; i < n; i++) {
    if (i != max_idx) {
      s += max - a[i];
    }
  }
  cout << s << endl;
  return 0;
}
