#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long ans = 0;
  long long ma = 0;
  long long a[n];
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (long long i = n - 2; i >= 0; --i) {
    ans = max(ans, a[i + 1] - a[i]);
    a[i] = max(a[i + 1], a[i]);
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T = 1;
  for (long long i = 1; i <= T; ++i) {
    solve();
  }
  return 0;
}
