#include <iostream>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    long long x;
    cin >> x;

    long long minVal = x;
    long long maxDiff = 0;

    for (int i = 2; i <= n; i++) {
        cin >> x;

        if (x > minVal) {
            long long diff = x - minVal;
            if (diff > maxDiff)
                maxDiff = diff;
        }

        if (x < minVal)
            minVal = x;
    }

    cout << maxDiff << "\n";

    return 0;
}
