#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);
}
