#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int fum = 0;
  ll res = 0;
  for (int i = 0; i < (int)(N); i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < (int)(N - 1); i++) {
    if (A.at(i) <= A.at(i + 1)) {
      continue;
    } else {
      fum = A.at(i) - A.at(i + 1);
      res += fum;
      cout << fum << endl;
      A.at(i + 1) = fum + A.at(i + 1);
    }
  }
  cout << res << endl;
}
