Sorted Arrangement#10615

Sorted Arrangement

2 seconds
128 megabytes
Medium

There is a container that is open from both ends and is always sorted. To insert an element, its position is determined, then each of the elements to the left or to the right of that position is removed. The new element is inserted, then the removed elements are added back. Each removal or insertion is an operation. Determine the minimum number of operations after inserting a list of integers into an empty list.

Input

The first line contains natural number (1 \le n \le 10^6). The next line contains integers in the range from to 10^6.

Output

Print the minimum number of operations to create the sorted list.

prb10615.gif

Examples

Example 1

Loading
Loading