#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int iter, sum = 0;
  cin >> iter;
  vector<int> array = {};
  for (int i = 0; i < iter; i++) {
    int virt;
    cin >> virt;
    array.emplace_back(virt);
  }
  for (int i = 1; i < iter; i++) {
    if (array[i] - array[i - 1] < 0) {
      sum += array[i - 1] - array[i];
      array[i] += array[i - 1] - array[i];
      cout << sum << "\n";
    }
  }
  cout << sum;
}
