#include <cstdio>
int n,tmp,min=0x7fffffff,max=0x80000000;
int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		if(max < tmp-min) max = tmp - min;
		if(min > tmp) min = tmp;
	}
	printf("%d\n",max);
	return 0;
}
