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.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Date: 23.06.13 at 16:42
 *
 * @author Nickolay Polyarniy aka PolarNick
 */
public class ProblemB {

    class pNode {
        Node node;
        pNode next;

        @Override
        public String toString() {
            if (node == null) {
                return "[null]" + next;
            } else {
                return "[" + node.value + "]" + next;
            }
        }
    }

    class Node {
        int value;
        boolean died = false;
        Node next;
        Node prev;

        @Override
        public String toString() {
            if (prev == null && next == null) {
                return "[null," + value + "," + "null]";
            }
            if (prev == null) {
                return "[null" + "," + value + "," + next.value + "]" + next;
            }
            if (next == null) {
                return "[" + prev.value + "," + value + "," + "null]";
            }
            return "[" + prev.value + "," + value + "," + next.value + "]" + next;
        }
    }

    public void solve() throws Exception {
        int n = nextInt();
        int[] a = readIntArray(n);
        Node first = new Node();
        first.value = a[0];
        first.prev = null;
        Node last = first;

        pNode firstP = new pNode();
        for (int i = 1; i < n; i++) {
            Node cur = new Node();
            cur.value = a[i];
            cur.prev = last;
            last.next = cur;
            last = cur;
            if (a[i - 1] > a[i] && firstP.next == null) {
                firstP.next = new pNode();
                firstP.next.node = cur;
            }
        }
        {
            pNode lastP = firstP.next;
            if (lastP != null) {
                Node cur = lastP.node.next;
                while (cur != null) {
                    if (cur.prev.value > cur.value) {
                        pNode curP = new pNode();
                        curP.node = cur;
                        lastP.next = curP;
                        lastP = curP;
                    }
                    cur = cur.next;
                }
            }
        }

        boolean changes = true;
        int res = 0;
        while (changes) {
//            out.println(first);
//            out.println(firstP);
//            out.flush();
            changes = false;
            pNode prevP = firstP;
            pNode curP = firstP.next;
            while (curP != null) {
                Node cur = curP.node;
                if (cur.prev.value > cur.value) {
                    changes = true;
                    cur.died = true;
                    if (cur.next != null) {
                        while (cur.next.prev.died) {
                            cur.next.prev = cur.next.prev.prev;
                        }
                    }
                    curP = curP.next;
                }

                while (cur.prev.died) {
                    cur.prev = cur.prev.prev;
                }
                cur.prev.next = cur;
                if (cur.died) {
                    cur.prev.next = cur.next;
                }
            }

            pNode lastP = firstP;
            curP = firstP.next;
            lastP.next = null;
            while (curP != null) {
                Node next = curP.node.next;
                if (next != null && !next.died && next.prev != null && next.prev.value > next.value) {
                    pNode newP = new pNode();
                    newP.node = next;
                    lastP.next = newP;
                    lastP = newP;
                }
                curP = curP.next;
            }
            if (changes) {
                res++;
            }
        }
        out.println(res);

    }

    public static void main(String[] args) throws Exception {
        ProblemB problem = new ProblemB();
        problem.solve();
        problem.close();
    }

    BufferedReader in;
    PrintWriter out;
    String curLine;
    StringTokenizer tok;
    final String delimeter = " ";
    final String endOfFile = "";

    public ProblemB(BufferedReader in, PrintWriter out) throws Exception {
        this.in = in;
        this.out = out;
        curLine = in.readLine();
        if (curLine == null || curLine.equalsIgnoreCase(endOfFile)) {
            tok = null;
        } else {
            tok = new StringTokenizer(curLine, delimeter);
        }
    }

    public ProblemB() throws Exception {
        this(new BufferedReader(new InputStreamReader(System.in)),
                new PrintWriter(System.out));
    }

    public ProblemB(String filename) throws Exception {
        this(new BufferedReader(new FileReader(filename + ".in")),
                new PrintWriter(filename + ".out"));
    }

    public boolean hasMore() throws Exception {
        if (tok == null || curLine == null) {
            return false;
        } else {
            while (!tok.hasMoreTokens()) {
                curLine = in.readLine();
                if (curLine == null || curLine.equalsIgnoreCase(endOfFile)) {
                    tok = null;
                    return false;
                } else {
                    tok = new StringTokenizer(curLine);
                }
            }
            return true;
        }
    }

    public String nextWord() throws Exception {
        if (!hasMore()) {
            return null;
        } else {
            return tok.nextToken();
        }
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextWord());
    }

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

    public int[] readIntArray(int n) throws Exception {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextInt();
        }
        return res;
    }

    public void close() throws Exception {
        in.close();
        out.close();
    }

}

