#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	ll mi;
	cin >> mi;
	ll ans = -1e10;
	for (int i = 0; i < n-1; ++i)
	{
		ll r;
		cin >> r;
		ans = max(ans, r-mi);
		mi = min(r, mi);
	}
	cout << ans << endl;
	return 0;
}
