#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, i, sum = 0, max;
  cin >> N;
  int A[N];
  for (i = 0; i <= N - 1; i++) cin >> A[i];
  max = *max_element(A, A + N);
  for (i = 0; i <= N - 1; i++) sum += (max - A[i]);
  cout << sum << endl;
  return 0;
}
