While they wait for the pizza from Trominos those that
have already showed up pass the time by watching some shows.
Since there weren’t a lot of suggestions Atli made a suggestion
no one bothered to protest, so the end result is everyone
watching Bogletics. At some point in the episode the main
character runs into some problems. He has
items and
places to store them. Since he
can only carry so much and already has quite a few things on
his person he can only carry one of these items at a time.
Currently the items are distributed among the first
places but not in the
order he would like them to be. The only thing he can do is
pick up an item and move it to an unoccupied place. How many
trips does he have to make to get everything where he wants it
to be?
Input
The first line of the input contains an integer satisfying , the number of
items that need to be placed in order. The next line contains
integers satisfying
. The
value of indicates
in what location the item at location should be at the end. No
will take the value
as place
should always be
empty at the beginning and end. All the will be distinct.
Output
One line with an integer which gives the minimum number of
moves to get the items to their desired locations.
Sample Input 1 |
Sample Output 1 |
4
1 3 2 4
|
3
|
Sample Input 2 |
Sample Output 2 |
8
7 4 6 8 1 3 5 2
|
11
|