The BeczkoBit factory produces barrels for pickling bytes. The production line is fully automated, and the bottleneck is the warehouse. In the warehouse the finished barrels must be lined up in order of size, from the smallest to the largest. All barrels have distinct sizes.
The sorting is carried out by a team of cranes. Each crane can swap the positions of any two barrels. The cranes work in parallel, and a single swap by one crane takes 1 unit of time. During any one unit of time each barrel may be moved by at most one crane, so two swaps performed in the same unit of time may not touch the same barrel.
Find the minimum time (number of time units) needed to arrange the barrels in ascending order of size.
The first line contains an integer n (1≤n≤100000), the number of barrels. The second line contains n distinct integers from {1,2,…,n}, giving the sizes of the barrels in the order they stand in the warehouse. The barrel in the first position is described by the first number, and the barrel in the last position by the last number.
Print a single integer on one line: the minimum number of time units needed to sort the barrels into ascending order of size.