#include <bits/stdc++.h>
int arr[105];
using namespace std;
int main() {
  int n, mx = 0;
  long long sum = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] > mx) mx = arr[i];
  }
  for (int i = 0; i < n; i++)
    if (arr[i] < mx) sum += (mx - arr[i]);
  cout << sum << endl;
  return 0;
}
