#include <bits/stdc++.h>
using namespace std;
int main() {
  int ppl, s = 0, maxn = 0;
  cin >> ppl;
  int wel[ppl];
  for (int j = 0; j < ppl; j++) {
    cin >> wel[j];
    if (maxn < wel[j]) {
      maxn = wel[j];
    }
  }
  for (int i = 0; i < ppl; i++) {
    s = s + maxn - wel[i];
  }
  cout << s;
  return 0;
}
