#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n;
  cin >> n;
  long long int arr[n + 1];
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long int max1 = 0, idx;
  for (long long int i = 0; i < n; i++) {
    max1 = max(max1, arr[i]);
  }
  for (long long int i = 0; i < n; i++) {
    if (arr[i] == max1) {
      idx = i;
      break;
    }
  }
  long long int max2 = 0;
  for (long long int i = 0; i < idx; i++) {
    max2 = max(max2, arr[i]);
  }
  long long int ans = 0;
  for (long long int i = 0; i < idx; i++) {
    ans += (max2 - arr[i]);
  }
  for (long long int i = idx; i < n; i++) {
    ans += (max1 - arr[i]);
  }
  cout << ans << "\n";
  return 0;
}
