#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, sum = 0;
  cin >> n;
  int a[n];
  for (int j = 0; j < n; j++) {
    cin >> a[j];
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i - 1] > a[i] && i >= 1) {
      sum += (a[i - 1] - a[i]);
      a[i] += (a[i - 1] - a[i]);
    }
  }
  cout << sum;
  return 0;
}
