#include <bits/stdc++.h>
using namespace std;
long long n, k, m, l, i, j, s, t, a[500000], ans, mx;
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i], mx = max(mx, a[i]);
  for (i = 1; i <= n; i++) ans += mx - a[i];
  cout << ans;
  return 0;
}
