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