#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int x, s = 0;
  while (cin >> x) {
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    s += (a[n - 1] - a[i]);
  }
  cout << s;
  return 0;
}
