#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int max = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] > max) max = A[i];
  }
  int sum = 0;
  for (int i = 0; i < N; i++) sum += max - A[i];
  cout << sum;
  return 0;
}
