#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[1000000], i, m, max, n, c = 0, sum = 0, s = 0;
  cin >> n;
  max = a[1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    if (a[i] > max) {
      max = a[i];
      c = i;
    }
  }
  m = a[1];
  for (i = 1; i < c - 1; i++) {
    if (a[i] > m) {
      m = a[i];
    }
  }
  for (i = 1; i <= c - 1; i++) sum = sum + m - a[i];
  for (i = c; i <= n; i++) s = s + max - a[i];
  cout << sum + s << endl;
  ;
}
