#include<iostream>
using namespace std;
typedef long long LL;
int main(){
LL n,tmp,minn,maxx;
cin>>n;
minn=1e15,maxx=-1e15;
for(int i=1;i<=n;i++){
scanf("%lld",&tmp);
if(minn>tmp){
minn=tmp;
continue;
}
if(tmp>minn){
LL t=tmp-minn;
maxx=max(maxx,t);
}
}
if(maxx==-1e15)cout<<"0"<<endl;
else cout<<maxx;
return 0;
}