Mirko has a home library consisting of books arranged one on top of the other in a narrow cabinet. Since being well trained in the secrets of alphabet in the previous task, he now wishes to arrange the books alphabetically, so that the book whose title comes first alphabetically ends up on top, and the alphabetically last one at the bottom of the pile.
Mirko can easily pull a book out of the cabinet, but it is difficult to push it back into the pile, so the book can only be returned to the top of the pile. Thus, the only available method of sorting the books is repeatedly pulling a book out of the pile and placing it on top of the pile. The books are labelled with integers from to , in alphabetical order. Therefore, Mirko wants them to be ordered as , counting from the top. For example, if and the starting order is , two moves are sufficient. First, he pulls out the book number and places it on top, so the pile becomes . After that, he does the same with book number , thus the pile becomes .
Help Mirko by calculating the minimum number of moves needed to sort a given starting order.
Input Specification
The first line of input contains the integer .
Each of the next lines contains a single positive integer. These integers represent the order of Mirko's books from top to bottom of the cabinet. Each of the integers appears exactly once.
Output Specification
The first and only line of output must contain the required minimum number of moves.
Sample Input 1
3
3
2
1
Sample Output 1
2
Sample Input 2
4
1
3
4
2
Sample Output 2
2
Comments