#include "bits/stdc++.h"
using namespace std;
const int N = 1010;
vector<int> a(N), b;
int n;
int main() {
while (cin >> n) {
int res = 0;
a.resize(n);
for (int i = 0; i < n; i ++) cin >> a[i];
for (int i = 0; i + 1 < n;) {
int j = i + 1;
if (a[j] < a[i]) {
i ++;
continue;
}
while (j < n && a[j] >= a[j - 1]) j ++;
if (j - i >= 2) res = max(res, a[j - 1] - a[i]);
i = j;
}
cout << res << '\n';
}
return 0;
}