#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2;
int n, a[MAXN], maxx, summ;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxx = max(a[i], maxx);
  }
  for (int i = 0; i < n; i++) summ += maxx - a[i];
  cout << summ;
}
