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