#include <bits/stdc++.h>
using namespace std;
int main() {
  int br = 0, n, q, t;
  cin >> n >> q;
  for (; n != 1; n--) {
    cin >> t;
    if (t < q)
      br += (q - t);
    else
      q = t;
  }
  cout << br << '\n';
  return 0;
}
