#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, br = 0;
  cin >> n;
  int citizens[n];
  for (int i = 0; i < n; i++) cin >> citizens[i];
  int max = citizens[0];
  for (int i = 1; i < n; i++)
    if (citizens[i] > max) max = citizens[i];
  for (int i = 0; i < n; i++)
    if (citizens[i] < max) br = br + (max - citizens[i]);
  cout << br << endl;
}
