#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  sort(ar, ar + n);
  for (int i = n - 2; i >= 0; i--) s += ar[n - 1] - ar[i];
  cout << s;
}
