#include <bits/stdc++.h>
int xmax(int x[], int k, int *pos) {
  int t, i;
  int curr_pos = 0;
  t = x[0];
  for (i = 1; i < k; i++) {
    if (x[i] > t) {
      t = x[i];
      curr_pos = i;
    }
  }
  *pos = curr_pos;
  return (t);
}
int main(void) {
  int n;
  int sum = 0;
  scanf("%d", &n);
  int arr[n];
  int max = 0;
  int pos = 0;
  int i = 0;
  for (; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  while (n != 0) {
    max = xmax(arr, n, &pos);
    for (i = pos + 1; i < n; i++) {
      sum = sum + (max - arr[i]);
    }
    n = pos;
  }
  for (i = pos + 1; i < n; i++) {
    sum = sum + (max - arr[i]);
  }
  n = pos;
  printf("%d", sum);
}
