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