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