#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0;
  int arr[100];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  if (n == 1) {
    puts("0");
    return 0;
  } else {
    sort(arr, arr + n);
    int sum = 0;
    for (int i = 0; i < n; i++) sum += arr[i];
    ans = n * arr[n - 1] - sum;
    printf("%d\n", ans);
  }
}
