#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long int solve() {
  long long int n;
  cin >> n;
  long long int ans = 0;
  long long int maxa = 0;
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    if (!i) {
      maxa = a;
    } else {
      maxa = max(maxa, a);
    }
    ans = maxa - a;
  }
  cout << ans;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
