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