#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  short n;
  cin >> n;
  unsigned long long int a, max = 0, sum = 0;
  for (short i = 0; i < n; i++) {
    cin >> a;
    sum += a;
    if (max < a) max = a;
  }
  cout << max * n - sum;
  return 0;
}
