#include <bits/stdc++.h>
using namespace std;
long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long mod = 1e9 + 7;
const long long N = 300050;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long test = 1;
  while (test--) {
    long long n;
    cin >> n;
    long long a[n], mx = 0;
    for (long long i = 0; i < n; i++) {
      cin >> a[i], mx = max(mx, a[i]);
    }
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      ans = max({ans, 0LL, mx - a[i]});
    }
    cout << ans << '\n';
  }
  return 0;
}
