#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int maxs = INT_MIN;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] > maxs) {
      maxs = arr[i];
    }
    sum += maxs - arr[i];
  }
  cout << sum << endl;
}
