#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> m;
    v.push_back(m);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    ans = ans + v[n - 1] - v[i];
  }
  cout << ans << endl;
  return 0;
}
