#include <bits/stdc++.h>
using namespace std;
int main() {
  int city_num;
  while (cin >> city_num) {
    int i;
    int max_num = 0;
    vector<int> array_money(city_num);
    for (int i = 0; i < city_num; i++) {
      cin >> array_money[i];
      if (max_num < array_money[i]) max_num = array_money[i];
    }
    int total = 0;
    for (i = 0; i < city_num; i++) {
      total += (max_num - array_money[i]);
    }
    cout << total << endl;
  }
  return 0;
}
