#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  int *p = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int a = 0;
  a = p[0];
  int d = 0;
  if (n == 1) {
    cout << 0;
    return 0;
  } else
    for (int i = 0; i < n; i++) {
      if (a < p[i]) {
        a = p[i];
        d = i;
      }
    }
  int counter = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] != a && i != d) {
      counter += a - p[i];
    }
  }
  cout << counter;
}
