#include <iostream>
using namespace std;
int main(){
    int N,temp,rt,m;
    cin>>N;
    cin>>m;
    rt = -1000000000;
    for(int i = 1;i<N;i++){
        cin>>temp;
        rt = max(temp-m,rt);
        if(temp<m)
            m = temp;
    }
    cout<<rt<<endl;
}

