#include <bits/stdc++.h>
using namespace std;
int x[105];
int main() {
  long long n, max = 0, t0t = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    if (x[i] > max) {
      max = x[i];
    }
  }
  for (int i = 0; i < n; i++) {
    t0t = t0t + (max - (x[i]));
  }
  cout << t0t;
  return 0;
}
