#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int result = 0;
  int maxindex = INT_MIN;
  int max = INT_MAX;
  for (int i = 0; i < n; i++) {
    if (max < arr[i]) {
      max = arr[i];
      maxindex = i;
    }
  }
  if (maxindex == 0) {
    cout << 0 << endl;
    return 0;
  }
  int temp;
  for (int i = 0; i < maxindex; i++) {
    if (i == 0)
      temp = arr[i];
    else {
      if (temp < arr[i])
        result = result;
      else {
        result = result + arr[i] - temp;
        temp = arr[i];
      }
    }
  }
  for (int i = maxindex; i < n; i++) result = result + max - arr[i];
  cout << result << endl;
}
