#include <bits/stdc++.h>
using namespace std;
int main() {
  int citizen, treasure_cost, total = 0;
  cin >> citizen;
  int burle[citizen];
  for (int i = 0; i < citizen; i++) {
    cin >> burle[i];
  }
  sort(burle, burle + citizen);
  for (int i = 0; i < citizen; i++) {
    total = total + burle[i];
  }
  treasure_cost = burle[citizen - 1] * citizen - total;
  cout << treasure_cost << endl;
}
