#include "bits/stdc++.h"
using namespace std;
int main() {
	int n;
	scanf("%d",&n);
	int ans=-(1<<30);
	int min_v,R;
	scanf("%d",&min_v);
	for(int i=1;i<n;i++) {
		scanf("%d",&R);
		ans=max(ans,R-min_v);
		min_v=min(min_v,R);
	}
	printf("%d\n",ans);
}