#include <bits/stdc++.h>
using namespace std;
void FIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  FIO();
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long ma = INT_MIN;
  long long index = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > ma) {
      ma = a[i];
      index = i;
    }
  }
  long long left = *max_element(a.begin(), a.begin() + index);
  long long right = *max_element(a.begin() + index, a.end());
  long long cnt = 0;
  for (long long i = 0; i < index; i++) {
    cnt += (left - a[i]);
  }
  for (long long i = index; i < n; i++) {
    cnt += (right - a[i]);
  }
  cout << cnt << '\n';
  return 0;
}
