Dividers

No attempts yetTime limit1sMemory limit128 MB

Problem

All integers from 11 to nn are written in a single row in some order, forming a sequence. This sequence is a permutation of the numbers 11 through nn.

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 kk-th element only if the first kk elements contain every number from 11 to kk exactly once. In other words, the first kk elements must equal the set {1,2,,k}\{1, 2, \ldots, k\}. In particular, a divider can always be placed right after the nn-th element, because the whole sequence is a permutation of 11 through nn.

Find the maximum number of dividers you can insert.

Input

The first line contains an integer nn (1n1061 \le n \le 10^6), the length of the sequence.

The second line contains a permutation p1,p2,,pnp_1, p_2, \ldots, p_n (1pin1 \le p_i \le n) of the numbers 11 through nn, separated by spaces, where pip_i is the ii-th number in the sequence.

Output

Print a single integer: the maximum number of dividers that can be inserted.

Hint

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 44 dividers in total.