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