#include <bits/stdc++.h>
using namespace std;
int max(int len, int *nums) {
  int i, _max = nums[0];
  for (i = 1; i < len; i++) {
    if (nums[i] > _max) _max = nums[i];
  }
  return _max;
}
int main() {
  int n;
  cin >> n;
  int a[100];
  int total = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    total = total + (max(i, a) - a[i]);
  }
  cout << total;
  while (1)
    ;
}
