#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0, sum = 0;
  cin >> n;
  int aray[n];
  for (int i = 0; i < n; i++) {
    cin >> aray[i];
    if (aray[i] > s) s = aray[i];
  }
  for (int i = 0; i < n; i++) {
    sum = sum + (s - aray[i]);
  }
  cout << sum;
}
