#include <bits/stdc++.h>
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    int i, a[n], max, s = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    max = a[0];
    for (i = 1; i < n; i++) {
      if (a[i] > max) max = a[i];
    }
    for (i = 0; i < n; i++) {
      s = s + max - a[i];
    }
    printf("%d\n", s);
  }
  return 0;
}
