#include <bits/stdc++.h>
using namespace std;
long long n, a[101], maxi = 0, total = 0;
signed main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    total += a[i];
    maxi = max(maxi, a[i]);
  }
  cout << maxi * n - total;
  return 0;
}
