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