#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j;
  cin >> n;
  long int ar[n], mx = 0, c = 0;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] > mx) mx = ar[i];
  }
  for (i = 0; i < n; i++) {
    c = c + abs(mx - ar[i]);
  }
  cout << c;
  return 0;
}
