#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, Max = 0, s = 0;
  cin >> n;
  int a[n + 2];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    Max = max(Max, a[i]);
  }
  for (int i = 0; i < n; i++) {
    s += Max - a[i];
  }
  cout << s;
}
