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