#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 par[N], sz[N], done[N], a[N], b[N];
map<int, int> mp;
signed main() {
int n;
cin >> n;
int mx = 0;
for(int i = 0; i < n; i++) cin >> a[i], mx = max(mx, a[i]), b[i] = a[i], mp[a[i]] = i;
for(int i = 0; i < n; i++) par[i] = i;
sort(b, b + n);
reverse(b, b + n);
int cur = 0, ans = 0;
for(int i = 1; i < n; i++){
cur++;
// if(i == 3){
// cout << mp[b[i - 1]] << endl;
// }
if(mp[b[i - 1]] > 0 and done[mp[b[i - 1]] - 1]){
cur--;
}
if(mp[b[i - 1]] < n - 1 and done[mp[b[i - 1]] + 1]){
//if(i == 3) cout << cur << endl;
cur--;
//if(i == 2) cout << "here" << endl;
}
done[mp[b[i - 1]]] = 1;
// if(cur == 2) cout << i << endl;
ans = max(ans, cur);
}
cout << ans << endl;
}