#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
const int mxn = 2e5 + 10;
int n;
long long a[mxn], b[mxn];
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  b[0] = a[0];
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      b[i] = a[i - 1];
      ans += b[i] - a[i];
      a[i] = b[i];
      std::cout << ans << '\n';
    }
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  for (int i = 1; i <= t; ++i) {
    solve();
  }
}
