#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, s = 0, sum = 0;
  cin >> n;
  int arr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] > s) s = arr[i];
  }
  for (i = 0; i < n; i++) sum = sum + s - arr[i];
  cout << sum << endl;
  return 0;
}
