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