#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int *a = new int[n]();
  int max = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max) {
      max = a[i];
    }
  }
  int total = 0;
  for (int i = 0; i < n; i++) {
    total += (max - a[i]);
  }
  cout << total << endl;
}
