#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  vector<int> v(x);
  long long total = 0;
  int max = 0;
  for (int i = 0; i < x; i++) {
    cin >> v[i];
    total += v[i];
    if (v[i] > max) max = v[i];
  }
  cout << max * x - total;
  return 0;
}
