#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int mini;
	cin>>mini;
	int ans=INT_MIN;
	for(int i=1; i<n; i++){
		int m;
		cin>>m;
		int tmp=m-mini;
		ans=max(tmp,ans);
		mini=min(m,mini);
	}
	cout<<ans<<endl;
}