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