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