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