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