#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  long long maxi = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > maxi) {
      maxi = a[i];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += maxi - a[i];
  }
  cout << ans;
}
