There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step. 

You're given the initial arrangement of the psychos in the line. Calculate how many steps are needed to the moment of time such, that nobody kills his neighbor after that moment. Look notes to understand the statement more precise.

Input

The first line of input contains integer n denoting the number of psychos, (1 ≤ n ≤ 105). In the second line there will be a list of n space separated distinct integers each in range 1 to n, inclusive — ids of the psychos in the line from left to right.

Output

Print the number of steps, so that the line remains the same afterward.

Examples

Input

10
10 9 7 8 6 5 3 4 2 1


Output

2


Input

6
1 2 3 4 5 6


Output

0

Note

In the first sample line of the psychos transforms as follows: [10 9 7 8 6 5 3 4 2 1]  →  [10 8 4] →  [10]. So, there are two steps.
// Created by Priyanshu

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;

#define M                    1000000007
#define pi                   3.14159265358979323846
#define ll                   long long
#define lld                  long double

// Pair
#define pii                  pair<int, int>
#define pll                  pair<ll, ll>

// Vector
#define vl                   vector<ll >
#define vi                   vector<int>
#define vpi                  vector<pii>
#define vpl                  vector<pll>
#define pb                   push_back
#define mp                   make_pair


// Search
#define lb                   lower_bound
#define ub                   upper_bound
#define mina                 *min_element
#define mama                 *max_element
#define bsrch                binary_search


////////
#define F                    first
#define S                    second
#define cel(x,a)             (((x) + (a) - 1) / (a))
#define all(v)               v.begin(), v.end()
#define countofbits(n)       __builtin_popcountll(n)
#define lcm(m, n)            (((m) / __gcd((m), (n)))*(n))
#define oset                 tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define deb(...)             cout << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__)
#define ms(arr, v)           memset(arr, v, sizeof(arr))
#define pf(x,y)              setfill('x')<<setw(y)
#define ps(x,y)              fixed << setprecision(y) << x
#define _X_                  ios_base::sync_with_stdio(false); cin.tie(NULL)
#define tolo(a)              transform(all(a), a.begin(), ::tolower)
#define toup(a)              transform(all(a), a.begin(), ::toupper)


///////////////////////////////

int II;
long long I_O;
char CC, SS[20];
const int N = 1e5 + 4;

///////////////////////////////


// Input / Output
#define scn(str)             scanf("%s", str)
#define pri(str)             printf("%s\n", str)
#define inp(a, n)            for(int Ele=0; Ele<(n); Ele++)a[Ele]=read()
#define inp1(a, n)           for(int Ele=1; Ele<=(n); Ele++)a[Ele]=read()
inline  ll  read()           { II = 1, I_O = 0; while (!isdigit(CC = getchar())) if (CC == '-') II = -1; while (isdigit(CC)) I_O = I_O * 10 + CC - '0', CC = getchar(); return I_O * II;}
inline void wonl()           { putchar('\n');}
inline void  wws()           { }
inline void  dbg()           { cout << endl; }
inline void ww(ll k)         { if (k < 0) putchar('-'), k *= -1; II = 0; while (k)SS[++II] = k % 10, k /= 10; if (!II) SS[++II] = 0; while (II)putchar(SS[II--] + '0');}
inline void ww(pll p)        { ww(p.F), putchar(' '), ww(p.S); }


// bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {return (a.S < b.S);}

// struct compare {
//     bool operator()(const pair<int, int>& value, const int& key) {return (value.F < key);}
//     bool operator()(const int& key, const pair<int, int>& value) {return (key < value.F);}
// };




template <typename T, typename... V>
inline void wonl(T t, V... v) {ww(t); if (sizeof...(v))putchar(' '); wonl(v...);}


template <typename T, typename... V>
inline void  wws(T t, V... v) {ww(t); putchar(' '); wws(v...);}


template <typename T, typename... V>
inline void  dbg(T t, V... v) {cout << ' ' << t; dbg(v...);}


void swws(auto a) {for (auto it : a)wws(it); wonl();}
void swws(auto a, int lin) {for (int i = 0; i < lin; i++)wws(a[i]); wonl();}
void swws(auto a, int lst, int lin) {for (int i = lst; i <= lin; i++)wws(a[i]); wonl();}


void swonl(auto a) {for (auto it : a)wonl(it);}
void swonl(auto a, int lin) {for (int i = 0; i < lin; i++)wonl(a[i]);}
void swonl(auto a, int lst, int lin) {for (int i = lst; i <= lin; i++)wonl(a[i]);}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////













void solve() {




    int n = read(), ar[n];
    inp(ar, n);

    map<int, int> ma;

    vi del;
    vi peak;


    for (int i = 0; i < n; i++)
        ma[i] = ar[i];


    int prev = -1;
    for (auto it : ma) {
        if (it.S <= prev)
            del.pb(it.F);
        prev = it.S;
    }



    int cnt = 0;
    while (1) {
        if (del.size() == 0) {
            wonl(cnt);
            return;
        }
        cnt++;
    
        for (auto it : del)
            ma.erase(it);


        auto it1 = ma.lb(del.front());
        it1--;
        auto it2 = ma.lb(del.back());


        del.clear();

        int prev = -1;
        for (auto itr = it1; itr != it2; itr++) {
            if (itr->S <= prev)
                del.pb(itr->F);
            prev = itr->S;
        }
    


        for (auto itr = it2; itr != ma.end(); itr++)
            if (itr->S <= prev)
                del.pb(itr->F), prev = itr->F;
            else break;

    }





}












int main()
{
    // _X_;
    // clock_t time_req = clock();


    solve();


    // time_req = clock() - time_req;
    // cout << (float)time_req / CLOCKS_PER_SEC;
    return 0;
}