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