#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fs first
#define sc second
using namespace std;
const int N = 1e6 + 6;
int done[N], a[N], b[N];
pair<int, int> p[N];
map<int, int> mp;
signed main() {
int n;
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i], p[i] = {a[i], i};
sort(p, p + n);
reverse(p, p + n);
int cur = 0, ans = 0;
for(int i = 1; i < n; i++){
cur++;
int idx = p[i - 1].sc;
if(idx > 0 and done[idx - 1]){
cur--;
}
if(idx < n - 1 and done[idx + 1]){
//if(i == 3) cout << cur << endl;
cur--;
//if(i == 2) cout << "here" << endl;
}
done[idx] = 1;
// if(cur == 2) cout << i << endl;
if(i < n - 1 and p[i - 1].fs != p[i].fs) ans = max(ans, cur);
}
cout << ans << endl;
}