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.math.BigInteger;
import java.util.*;



public class B {
    private static final int mod = (int)1e9+7;
    
    public void run() throws IOException {
        final int n = IOFast.nextInt();
        int[] hi = new int[n];
        int[] h = new int[n];
        
        int[] cnt = new int[n];
        int ans = 0;
        for(int j = 0, i = 0; i < n; i++) {
            hi[j] = i;
            h[j] = IOFast.nextInt();
            if(j >= 1 && h[j-1] > h[j]) {
                cnt[hi[j-1]]++;
            }
            if(j >= 1 && h[j] > h[j-1]) {
                while(j >= 1 && h[j] > h[j-1]) {
                    if(j >= 2) {
                        cnt[hi[j-2]] = Math.max(cnt[hi[j-1]], cnt[hi[j-2]]);
                    }
                    h[j - 1] = h[j];
                    hi[j - 1] = hi[j];
                    j--;
                }
                if(j >= 1) {
                    cnt[hi[j-1]]++;
                }
            }
            j++;
        }
        for(int x : cnt) ans = Math.max(ans, x);
        
        IOFast.out.println(ans);
    }
    
    static
    class BIT {
        final int n;
        final int[] bit;

        public BIT(int size) {
            n = size;
            bit = new int[n + 1];
        }
        
        public void clear() { Arrays.fill(bit, 0); }

        public int sum(int i) {
            int res = 0;
            for (; i > 0; i -= i & -i) {
                res += bit[i];
//              while(res >= mod) res -= mod;
            }
            return res;
        }

        // 1<=i<=n
        public void add(int i, int x) {
            for (; i <= n; i += i & -i) {
                bit[i] += x;
//              while(bit[i] >= mod) bit[i] -= mod;
            }
        }
    }

    
    public static void main(String[] args) throws IOException {
        //      IOFast.setFileIO("input.txt", "output.txt");
        new B().run();
        IOFast.out.flush();
    }
    

    static public class IOFast {
        private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        private static PrintWriter out = new PrintWriter(System.out);

        static void setFileIO(String ins, String outs) throws IOException {
            try {
                in = new BufferedReader(new FileReader(ins));
                out = new PrintWriter(new FileWriter(outs));
            }
            catch(IOException e) {
                System.err.println(e);
                throw e;
            }
        }

        //      private static final int BUFFER_SIZE = 50 * 200000;
        private static int pos, readLen;
        private static final char[] buffer = new char[1024 * 8];
        private static final StringBuilder buf = new StringBuilder();
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];

        static {
            for(int i = 0; i < 10; i++) {
                isDigit['0' + i] = true;
            }
            isDigit['-'] = true;
            isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
        }

        static boolean endInput;

        private static int read() throws IOException {
            if(readLen == -1) {
                return -1;
            }

            if(pos >= readLen) {
                readLen = in.read(buffer);
                pos = 0;

                if(readLen <= 0) {
                    return -1;
                }
            }

            return buffer[pos++];
        }

        private static int nextInt() throws IOException {
            boolean plus = false;
            int ret = 0;
            while(true) {
                final int c = read();

                if(c == -1) {
                    endInput = true;
                    return Integer.MIN_VALUE;
                }

                if(isDigit[c]) {
                    if(c != '-') {
                        plus = true;
                        ret = c - '0';
                    }
                    break;
                }
            }

            while(true) {
                final int c = read();
                if(c == -1 || !isDigit[c]) {
                    break;
                }
                ret = ret * 10 + c - '0';
            }

            return plus ? ret : -ret;
        }

        private static long nextLong() throws IOException {
            boolean plus = false;
            long ret = 0;
            while(true) {
                final int c = read();

                if(c == -1) {
                    endInput = true;
                    return Integer.MIN_VALUE;
                }

                if(isDigit[c]) {
                    if(c != '-') {
                        plus = true;
                        ret = c - '0';
                    }
                    break;
                }
            }

            while(true) {
                final int c = read();
                if(c == -1 || !isDigit[c]) {
                    break;
                }
                ret = ret * 10 + c - '0';
            }

            return plus ? ret : -ret;
        }

        private static char nextChar() throws IOException {
            while(true) {
                final int c = read();

                if(c == -1) {
                    endInput = true;
                    return '\0';
                }

                if(!isSpace[c]) {
                    return (char)c;
                }
            }
        }

        private static String next() throws IOException {
            buf.setLength(0);

            while(true) {
                final int c = read();

                if(c == -1) {
                    endInput = true;
                    return "-1";
                }

                if(!isSpace[c]) {
                    buf.append((char)c);
                    break;
                }
            }

            while(true) {
                final int c = read();

                if(c == -1 || isSpace[c]) {
                    break;
                }
                buf.append((char)c);
            }

            return buf.toString();
        }

        private static double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

    }

}
