#include <bits/stdc++.h>
using namespace std;
int a[200000 + 5];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, index, ind;
  cin >> n;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > mx) {
      mx = a[i];
      index = i;
    }
  }
  int lx = a[0];
  for (int i = 1; i < index - 1; i++) {
    if (a[i] > lx) lx = a[i];
  }
  int temp = lx;
  long long sum = 0, tsum = 0;
  for (int i = 1; i < index; i++) {
    sum += lx - a[i];
  }
  for (int i = index + 1; i < n; i++) {
    tsum += mx - a[i];
  }
  cout << tsum + sum << "\n";
  return 0;
}
