Rotating the Keyring

No attempts yetTime limit1sMemory limit64 MB

Problem

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 NN keys on one big round pendant, blindfolded him, and led him into a large room. The room holds NN locked doors, numbered 1 to NN. 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 KKth 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.

Input

The first line contains the integers NN and KK (1N1000001 \le N \le 100000, 1K10000000001 \le K \le 1000000000).

The iith of the next NN lines contains the integer viv_i (1viN1 \le v_i \le N), meaning that the iith key on the pendant, counted from the left, opens door viv_i. Different keys open different doors, so v1,v2,,vNv_1, v_2, \dots, v_N is a permutation of the numbers 1 to NN.

Output

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 KKth door.

Explanation

Take N=4N = 4, K=6K = 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.

  • unlocking 1 (door 1): 4 2 1 3, 2 wrong tries
  • unlocking 2 (door 2): 1 3 4 2, 3 wrong tries
  • unlocking 3 (door 3): 2 1 3 4, 2 wrong tries
  • unlocking 4 (door 4): 3 4 2 1, 1 wrong try
  • unlocking 5 (door 1): 4 2 1 3, 2 wrong tries
  • unlocking 6 (door 2): 1 3 4 2, 3 wrong tries

The wrong tries add up to 13.