All integers from 1 to n are written in a single row in some order, forming a sequence. This sequence is a permutation of the numbers 1 through n.
You want to insert as many dividers into this sequence as possible. A divider can be placed between two adjacent elements of the sequence (or at the very end).
You may place a divider right after the k-th element only if the first k elements contain every number from 1 to k exactly once. In other words, the first k elements must equal the set {1,2,…,k}. In particular, a divider can always be placed right after the n-th element, because the whole sequence is a permutation of 1 through n.
Find the maximum number of dividers you can insert.
The first line contains an integer n (1≤n≤106), the length of the sequence.
The second line contains a permutation p1,p2,…,pn (1≤pi≤n) of the numbers 1 through n, separated by spaces, where pi is the i-th number in the sequence.
Print a single integer: the maximum number of dividers that can be inserted.
For example, when the sequence is 2 1 3 6 5 4 9 10 8 7, the dividers can be placed as follows: 2 1 | 3 | 6 5 4 | 9 10 8 7 |. In this case there are 4 dividers in total.