#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b[103];
  while (cin >> a) {
    for (int i = 0; i < a; i++) cin >> b[i];
    sort(b, b + a);
    int c = b[a - 1];
    int sum = 0;
    for (int i = 0; i < a; i++) sum += (c - b[i]);
    cout << sum << endl;
  }
  return 0;
}
