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

int main(){
	int n;
	cin >> n;
	
	int minR = 1000000000;
	int ans = -1000000000;
	
	for(int i=0; i<n; i++){
		int r;
		cin >> r;
		if(i!=0)ans = max(ans, r - minR);
		minR = min(minR, r);
	}
	
	cout << ans << endl;
	
	return 0;
}
