#include <iostream>

using namespace std;

int main(){
	long long int n,tmp,min=1000000000000,max=-1000000000000;
	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>tmp;
		if(max < tmp-min) max = tmp - min;
		if(min > tmp) min = tmp;
	}
	cout<<max<<endl;
	return 0;
}
