#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int ctzNum;
  cin >> ctzNum;
  long long int sal[ctzNum];
  for (long long int i = 0; i < ctzNum; i++) cin >> sal[i];
  sort(sal, sal + ctzNum, greater<long long int>());
  long long int m = sal[0];
  long long int count2 = 0;
  for (long long int i = 0; i < ctzNum; i++) {
    count2 += abs(m - sal[i]);
  }
  cout << count2 << endl;
  return 0;
}
