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.
// Goods things are coming, just keep believing
 
#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 FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mpp make_pair
#define endl '\n'
#define ff first 
#define int long long
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 1e5 + 5;
const int LG = 20;
const int mod = 1e9 + 7;

int arr[N];

class node
{
public:
     int data;
     node * next;
     node(int data)
     {
          this -> data = data;
          next = NULL;
     }
};

void print(node * curr)
{
     while(curr)
     {
          trace(curr -> data);
          curr = curr -> next;
     }
}

void solve()
{
     int n;
     cin >> n;
     node* curr = NULL;
     node* head = NULL;
     for(int i = 0; i < n; i++)
     {
          cin >> arr[i];
          node* temp = new node(arr[i]);
          head = temp;
          temp -> next = curr;
          curr = temp;
     }
     int ret = 0;
     curr = head;
     // print(curr);
     while(true)
     {
          int ok = 0;
          node * curr = head;
          node * start = NULL;
          node * newhead = NULL;
          int nudes = 0;
          while(curr and curr -> next)
          {
               if(curr -> data < curr -> next -> data)
               {
                    ok++;
               }
               else
               {
                    // trace(curr -> data);
                    node* temp = new node(curr -> data);
                    if(newhead == NULL)
                    {
                         newhead = temp;
                         start = temp;
                    }
                    else
                    {
                         start -> next = temp;
                         start = temp;
                    }
                    nudes++;
               }
               curr = curr -> next;
          }
          node* temp = new node(curr -> data);
          if(newhead == NULL)
          {
               newhead = temp;
               start = temp;
          }
          else
          {
               start -> next = temp;
          }
          nudes++;
          curr = head;
          while (curr != NULL)  
          {  
              node * next = curr->next;  
              free(curr);  
              curr = next;  
          } 
          if(!ok)
          {
               break;
          }
          if(ok == 1)
          {
               ret += nudes;
               break;
          }
          ret++;
          // print(newhead);
          head = newhead;
     }
     cout << ret << endl;
}
 
int32_t main()
{
     ios_base:: sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     #ifndef ONLINE_JUDGE
         freopen("input.txt", "r", stdin);
         freopen("output.txt", "w", stdout);
     #endif
     int t = 1;
     // cin >> t;
     while(t--)
     {
          solve();
     }
     return 0;
}