#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);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long cnt = 0;
  long long ma = *max_element(a.begin(), a.end());
  long long max_index = max_element(a.begin(), a.end()) - a.begin();
  for (long long i = n - 1; i > max_index; --i) {
    if (a[i] == ma) {
      break;
    }
    cnt = cnt + (ma - a[i]);
  }
  long long m = *max_element(a.begin(), a.begin() + max_index);
  for (long long i = 0; i < max_index; i++) {
    cnt += (m - a[i]);
  }
  cout << cnt << '\n';
  return 0;
}
