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