#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, a, minn, maxdif = 0;
    cin >> n;
    cin >> a;
    minn = a;
    for(int i = 1; i < n; i ++)
    {
        cin >> a;
        if(a > minn) maxdif = max(maxdif, a - minn);
        else minn = a;
    }
    cout << maxdif << endl;
    return 0;
}
