///SEGMENT MAP DP
#include<bits/stdc++.h>


using namespace std;

const int MAXN = 2e5+5;
int n,a[MAXN];

int l[MAXN],r[MAXN];
void read()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

map<pair<int,int>,int>dp;

pair<int,int> tree[4*MAXN];
int ql,qr;

pair<int,int> Merge(pair<int,int> p1, pair<int,int>p2)
{
    if(p1.first >= p2.first) return p1;
    return p2;
}
void make_tree(int v, int l, int r)
{
    if(l == r)
    {
        tree[v] = {a[r],r};
        return;
    }
    int mid = (l+r)/2;
    make_tree(v*2+0,l,mid+0);
    make_tree(v*2+1,mid+1,r);
    tree[v] = Merge(tree[v*2+0],tree[v*2+1]);
}

void update(int v, int l, int r)
{
    if(l == r)
    {
        tree[v] = {0,0};
        return;
    }
    int mid = (l+r)/2;
    if(qr <= mid) update(v*2+0,l,mid+0);
    else update(v*2+1,mid+1,r);
    tree[v] = Merge(tree[v*2+0],tree[v*2+1]);
}

pair<int,int> query(int v, int l, int r)
{
    if(r < ql || qr < l || l > r) return {0,0};
    if(ql <= l && r <= qr) return tree[v];
    int mid = (l+r)/2;
    pair<int,int>p1 = query(v*2+0,l,mid+0);
    pair<int,int>p2 = query(v*2+1,mid+1,r);

    return Merge(p1,p2);
}

int rec(int l, int r)
{
    if(l > r) return 0;
    if(l == r) return 1;
    if(dp.find({l,r}) != dp.end()) return dp[{l,r}];

    //cout << "IN REC " << l << " " << r << endl;
    dp[{l,r}] = 1;
    ql = l;
    qr = r;

    int last = l;
    int new_dp = 0;

    pair<int,int> maxch = query(1,1,n);

    //cout << maxch.first << " " << maxch.second << endl;
    new_dp = max(new_dp,rec(last,maxch.second-1));
    last = maxch.second+1;

    ql = qr = maxch.second;
    update(1,1,n);


    if(maxch.first == 0) return 1;

    while(true)
    {
        ql = l;
        qr = r;
        pair<int,int> pom = query(1,1,n);
        if(pom.first != maxch.first) break;
        maxch = pom;

        new_dp = max(new_dp,rec(last,maxch.second-1));
        last = maxch.second+1;

        ql = qr = maxch.second;
        update(1,1,n);
    }
    new_dp = max(new_dp,rec(last,r));

    dp[{l,r}] = new_dp + 1;
    return dp[{l,r}];
}

void solve()
{
    make_tree(1,1,n);
    cout << rec(1,n) << endl;
}

int main()
{

	read();
	solve();
    return 0;
}
