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.
import java.io.*;
import java.util.*;
public final class psychos_in_a_line
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static int[] a,log,tree,dp;
	static int[][] st;
	static int maxn=(int)2e5,n;
	
	static void buildST()
	{
		log=new int[maxn];
		for(int i=2;i<maxn;i++)
		{
			log[i]=log[i>>1]+1;
		}
		st=new int[log[maxn-1]][n+5];
		for(int i=1;i<=n;i++)
		{
			st[0][i]=i;
		}
		for(int mask=1;(1<<mask)<=n+1;mask++)
		{
			for(int i=1;i+(1<<mask)<=n+1;i++)
			{
				int x=st[mask-1][i],y=st[mask-1][i+(1<<(mask-1))];
				st[mask][i]=(a[x]>=a[y]?x:y);
			}
		}
	}
	
	static int getMax(int l,int r)
	{
		int val=log[r-l],x=st[val][l],y=st[val][r-(1<<val)+1];
		return (a[x]>=a[y]?x:y);
	}
	
	static void update(int node,int s,int e,int l,int r,int val)
	{
		if(s>e || l>e || r<s)
		{
			return;
		}
		if(s==e)
		{
			tree[node]=val;
		}
		else
		{
			int mid=(s+e)>>1;
			update(node<<1,s,mid,l,r,val);update(node<<1|1,mid+1,e,l,r,val);
			tree[node]=Math.max(tree[node<<1],tree[node<<1|1]);
		}
	}
	
	static int maxx(int node,int s,int e,int l,int r)
	{
		if(s>e || l>e || r<s)
		{
			return 0;
		}
		if(l<=s && r>=e)
		{
			return tree[node];
		}
		else
		{
			int mid=(s+e)>>1;
			int q1=maxx(node<<1,s,mid,l,r),q2=maxx(node<<1|1,mid+1,e,l,r);
			return Math.max(q1,q2);
		}
	}
	
    public static void main(String args[]) throws Exception
    {
		n=sc.nextInt();a=new int[n+1];dp=new int[n+1];tree=new int[4*(n+1)];
		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextInt();
		}
		buildST();
		for(int i=2;i<=n;i++)
		{
			if(a[i-1]>a[i])
			{
				dp[i]=1;update(1,1,n,i,i,dp[i]);
			}
			else
			{
				int low=1,high=i;
				while(low<high)
				{
					int mid=(low+high)>>1,curr=getMax(i-mid,i);
					if(a[curr]>a[i])
					{
						high=mid;
					}
					else
					{
						low=mid+1;
					}
				}
				if(a[i-low]>a[i])
				{
					int curr=maxx(1,1,n,i-low+1,i-1);dp[i]=curr+1;update(1,1,n,i,i,dp[i]);
				}
			}
		}
		int max=0;//out.println(Arrays.toString(dp));
		for(int i=1;i<=n;i++)
		{
			max=Math.max(max,dp[i]);
		}
		out.println(max);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}