#include <bits/stdc++.h>
using namespace std;

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