#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, count = 0, count1 = 0, ans = 0, i, ma;
  cin >> n;
  long long int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  ma = a[0];
  for (i = 0; i < n; i++) {
    if (a[i] > ma) {
      ma = a[i];
    }
  }
  for (i = 0; i < n; i++) {
    count = ma - a[i];
    ans = ans + count;
  }
  cout << ans << "\n";
}
