#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 + 10;
int n, a[maxN], sum, maxx;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > maxx) maxx = a[i];
  }
  for (int i = 0; i < n; i++) {
    sum += maxx - a[i];
  }
  cout << sum << endl;
  return 0;
}
