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