#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    v.push_back(t);
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int M = -1;
  for (auto itr = v.begin(); itr != v.end(); itr++) {
    if (*itr > M) M = *itr;
  }
  int ans = 0;
  for (auto itr = v.begin(); itr != v.end(); itr++) {
    ans += (M - *itr);
  }
  cout << ans << endl;
}
