#include <bits/stdc++.h>
int main() {
  int n, max = INT_MIN, i, total = 0;
  scanf("%d", &n);
  int citizen[n];
  for (i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    citizen[i] = x;
    if (x > max) {
      max = x;
    }
  }
  for (i = 0; i < n; i++) {
    total = total + max - citizen[i];
  }
  printf("%d", total);
}
