#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<pair<int, int>> info;

vector<vector<int>> fillSubarr(vector<int> seq) {
    vector<vector<int>> subs;
    for (int sz = seq.size(); sz > 0; sz--) {
        for (int i = 0; i < sz - 1; i++) {
            vector<int> tmp;
            tmp.push_back(seq[i]);
            for (int j = i + 1; j < sz; j++) {
                tmp.push_back(seq[j]);
            }
            subs.push_back(tmp);
        }
    }
    for (int i = 0; i < subs.size(); i++) {
        for (int j = 0; j < subs[i].size(); j++) sort(subs[i].begin(), subs[i].end());
    }
    for (int i = 0; i < subs.size(); i++) {
        pair<int, int> tmp;
        tmp.first = subs[i][subs[i].size() - 2];
        tmp.second = subs[i].size();
        info.push_back(tmp);
    }
    return subs;
}

int main () {
    int n;
    cin >> n;
    vector<int> seq;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        seq.push_back(tmp);
    }
    vector<vector<int>> subs = fillSubarr(seq);
    
    int best = info[0].first - info[0].second;
    for (int i = 1; i < info.size(); i++) {
        if (best < info[i].first - info[i].second) {
            best = info[i].first - info[i].second;
        }
    }
    cout << best;
}
