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