#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i = 0, j, n, t, x, m, mx = 0, mn = 100000000, ans = 0, sum = 0;
  string s, a;
  bool flag = 0, f = 0;
  cin >> n;
  long long int b[n + 1];
  sum = 0;
  for (i = 0; i < n;) {
    cin >> b[i];
    mx = max(mx, b[i]);
    i++;
  }
  for (i = 0; i < n; i++) {
    sum += mx - b[i];
  }
  cout << sum << endl;
  return 0;
}
