#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> v;
  long long m = 0, s = 0, x = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
    m = max(m, x);
  }
  for (int i = 0; i < n; i++) {
    s += m - v[i];
  }
  cout << s << endl;
}
