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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedInputStream;
import java.util.PriorityQueue;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.File;
import java.util.AbstractCollection;
import java.io.FilterInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Atharva Nagarkar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        JoltyScanner in = new JoltyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemBPsychosInALine solver = new ProblemBPsychosInALine();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemBPsychosInALine {
        public void solve(int testNumber, JoltyScanner in, PrintWriter out) {
            int n = in.nextInt();
            Node[] nodes = new Node[n];
            for (int i = 0; i < n; ++i) nodes[i] = new Node(in.nextInt(), i);
            for (int i = 0; i < n; ++i) {
                if (i + 1 < n) nodes[i].next = nodes[i + 1];
                if (i - 1 >= 0) nodes[i].prev = nodes[i - 1];
            }
            PriorityQueue<Node> q = new PriorityQueue<>();
            for (int i = 1; i < n; ++i)
                if (nodes[i].val < nodes[i - 1].val) {
                    q.add(nodes[i]);
                    nodes[i].visited = true;
                    nodes[i].ans = 1;
                }
            int ans = 0;
            while (!q.isEmpty()) {
                Node cur = q.poll();
                ans = Math.max(ans, cur.ans);
                Node prev = cur.prev, next = cur.next;
                if (prev != null) {
                    prev.next = next;
                }
                if (next != null) {
                    next.prev = prev;
                }
                if (next != null && prev != null && prev.val > next.val && !next.visited) {
                    next.visited = true;
                    next.ans = cur.ans + 1;
                    q.add(next);
                }
            }
            out.println(ans);
        }

        class Node implements Comparable<Node> {
            Node prev;
            Node next;
            boolean visited = false;
            int val;
            int ans;
            int index;

            Node(int v, int i) {
                index = i;
                val = v;
            }

            public int compareTo(Node o) {
                if (ans == o.ans) return index - o.index;
                return ans - o.ans;
            }

            public String toString() {
                return "" + val;
            }

        }

    }

    static class JoltyScanner {
        public int BS = 1 << 16;
        public char NC = (char) 0;
        public byte[] buf = new byte[BS];
        public int bId = 0;
        public int size = 0;
        public char c = NC;
        public double num = 1;
        public BufferedInputStream in;

        public JoltyScanner(InputStream is) {
            in = new BufferedInputStream(is, BS);
        }

        public JoltyScanner(String s) throws FileNotFoundException {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        }

        public char nextChar() {
            while (bId == size) {
                try {
                    size = in.read(buf);
                } catch (Exception e) {
                    return NC;
                }
                if (size == -1) return NC;
                bId = 0;
            }
            return (char) buf[bId++];
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            num = 1;
            boolean neg = false;
            if (c == NC) c = nextChar();
            for (; (c < '0' || c > '9'); c = nextChar()) {
                if (c == '-') neg = true;
            }
            long res = 0;
            for (; c >= '0' && c <= '9'; c = nextChar()) {
                res = (res << 3) + (res << 1) + c - '0';
                num *= 10;
            }
            return neg ? -res : res;
        }

    }
}

