#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n];
  long long m = INT_MIN, x = -1;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (m < arr[i]) {
      m = arr[i];
      x = i;
    }
  }
  long long y = arr[0];
  long long sum = 0;
  for (int i = 0; i < x; i++) {
    if (arr[i] < y) {
      sum += (y - arr[i]);
    }
  }
  for (int i = x; i < n; i++) {
    if (arr[i] < m) {
      sum += (m - arr[i]);
    }
  }
  cout << sum << endl;
}
