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