#include <bits/stdc++.h>
using namespace std;
int n, cnt = 0, a[1000000], b, c = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (b = 0; b <= n - 1; b++) {
    cin >> a[b];
    if (c < a[b]) c = a[b];
  }
  for (b = 0; b <= n - 1; b++) cnt = cnt + c - a[b];
  cout << cnt;
}
