#include <bits/stdc++.h>
using namespace std;
long long n, k, q, mas[1000000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> mas[i];
  k = mas[0];
  for (int i = 1; i < n; i++) {
    if (mas[i] > k) k = mas[i];
  }
  for (int i = 0; i < n; i++) {
    q = q + k - mas[i];
  }
  cout << q;
}
