#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, max;
  max = 0;
  vector<int> z;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (max <= a) max = a;
    z.push_back(a);
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += max - z[i];
  }
  cout << sum;
  return 0;
}
