#include <bits/stdc++.h>
using namespace std;
namespace{
// Types
#define ll long long
#define ull unsigned long long
// Shortcuts
#define sp " "
#define endl "\n"
#define ft first
#define se second
#define pb push_back
#define pob pop_back
#define __Orion__ signed main()
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// Functions
#define sz(s) (s).size()
#define all(s) (s).begin(), (s).end()
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; i--)
#define file(a) freopen(a".INP", "r", stdin); freopen(a".OUT", "w", stdout)
// Const
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = 3.1415926535897932384626433832795;
}
const int mx = 2e6 + 5;
int n, ans, maxx, t, s[mx], ma[mx], pos[mx];
stack<int> st;
__Orion__{
fast;
//file("test1");
cin >> n;
FOR(i, 1, n) cin >> s[i];
FOR(i, 1, n){
if(s[i] > ma[i - 1]) t++;
ma[i] = max(ma[i - 1], s[i]);
pos[i] = t;
}
FORD(i, n, 1){
while(!st.empty() && st.top() <= s[i]) st.pop();
st.push(s[i]);
if(sz(st) == 1) maxx = st.top();
auto it = upper_bound(ma + 1, ma + n + 1, maxx);
int p = it - ma, k = sz(st);
if(p < i) k+=pos[i - 1] - pos[p] + 1;
ans = max(ans, k);
}
cout << ans;
cerr << "Time elapsed: " << TIME << sp << "s." << endl;
return (0 ^ 0);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKbmFtZXNwYWNlewogICAgLy8gVHlwZXMKICAgICNkZWZpbmUgbGwgbG9uZyBsb25nCiAgICAjZGVmaW5lIHVsbCB1bnNpZ25lZCBsb25nIGxvbmcKCiAgICAvLyBTaG9ydGN1dHMKICAgICNkZWZpbmUgc3AgIiAiCiAgICAjZGVmaW5lIGVuZGwgIlxuIgogICAgI2RlZmluZSBmdCBmaXJzdAogICAgI2RlZ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