The economy is bad, a crisis has hit the country, and many people have lost their jobs. Sisyphus found a new job anyway. Starting next Monday he works as an assistant locksmith in a hotel. First he has to show the head locksmith what he can do.
The head locksmith handed Sisyphus N keys on one big round pendant, blindfolded him, and led him into a large room. The room holds N locked doors, numbered 1 to N. Each key on the pendant opens exactly one door.
Sisyphus has to unlock every door and lock it again. He walks along the wall without changing direction until he reaches a door. At a door he tries the leftmost key on the pendant. If that key does not open the door, he moves it to the right end of the pendant and repeats the procedure until he finds the right key. The key that opens the door stays where it is, at the left end. The first door Sisyphus unlocked is numbered 1, the next one 2, the one after that 3, and so on.
One thing Sisyphus does not know: the head locksmith is testing his endurance and led him into a circular room. After unlocking and locking the last door he returns to the first door and carries on with the same work. Sisyphus is hardworking and persistent, so he kept at it for hours without a word. Only after the Kth successful unlocking and locking of a door did he speak: "If only I knew how many times so far I have put a wrong key in a lock!" Answer his question.
The first line contains the integers N and K (1≤N≤100000, 1≤K≤1000000000).
The ith of the next N lines contains the integer vi (1≤vi≤N), meaning that the ith key on the pendant, counted from the left, opens door vi. Different keys open different doors, so v1,v2,…,vN is a permutation of the numbers 1 to N.
Print one integer, the answer to Sisyphus' question: how many times he put a wrong key in a lock before he finished unlocking and locking the Kth door.
Take N=4, K=6 and the keys 4, 2, 1, 3 from left to right. The state of the pendant right before each door, and the number of wrong tries at that door, is this.
The wrong tries add up to 13.