#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc, i, j, k;
  cin >> tc;
  std::vector<int> a(tc);
  int mx = -1;
  int n = tc;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(a[i], mx);
  }
  int ans = 0;
  for (i = 0; i < n; i++) {
    ans += mx - a[i];
  }
  cout << ans << endl;
  return 0;
}
