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