#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> a;
  long long int val;
  for (long long int i = 0; i < n; i++) {
    cin >> val;
    a.push_back(val);
  }
  sort(a.begin(), a.end());
  if (n == 1) {
    cout << "0" << '\n';
    return 0;
  }
  long long int ans = 0, mx = 0;
  for (long long int i = 0; i < n; i++) {
    ans += a[i];
    mx = max(mx, a[i]);
  }
  cout << n * mx - ans << '\n';
  return 0;
}
