#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int n;
int a[200000];
int ans[200000];

int solve(int idx) {
    if (ans[idx] != 0) return ans[idx];

    int ans1 = 0;
    for (int i = idx-1; i >= 0; i--) {
        if (a[i] >= a[idx]) break;
        ans1 = max(ans1, ans[i]);
    }

    int ans2 = 0;
    for (int i = idx+1; i < n; i++) {
        if (a[i] >= a[idx]) break;
        ans2 = max(ans2, ans[i]);
    }

    return ans[idx] = max(ans1, ans2)+1;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
        v[i] = {a[i], i};
    }
    sort(v.begin(), v.end());

    int ans = 0;
    for (auto p: v) {
        ans = max(ans, solve(p.second));
    }

    cout << ans << endl;

    return 0;
}
