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