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