#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int arr[n];
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long int p = *max_element(arr, arr + n);
  long long sum = 0;
  for (long long int i = 0; i < n; i++) {
    if (p == arr[i]) {
      while (i != n) {
        sum += (p - arr[i]);
        i++;
      }
    } else {
      sum += abs(arr[0] - arr[i]);
    }
  }
  cout << sum;
}
