Table Tennis Team Lineup

No attempts yetTime limit1sMemory limit64 MB

Problem

The annual table tennis team competition for students of the University of Zagreb takes place next Saturday. Each team consists of KK students, and NN students are waiting in a queue to register.

Krešo works at the registration desk. He does not feel like doing his job, so he decided that students may not pick their own team. The first KK students in the queue form the first team, the next KK students form the second team, the next KK students form the third team, and so on. NN is divisible by KK, so no student is left without a team.

Ante has rated the skill of every student with one integer. He wants the KK weakest students in the first team, the next KK weakest in the second team, the next KK weakest in the third team, and so on, so the teams get stronger from the front of the queue to the back. Students who end up in the same team may stand in any order among themselves.

Krešo has just gone on a break, so Ante decided to shuffle the queue himself. Ante can tell one student to step out of the queue and stand back in it behind another student, or to go to the front of the queue. Moving one student this way takes him one minute.

Krešo may come back at any moment, so Ante needs to reach his goal as fast as possible. Determine the minimum number of minutes Ante needs.

Input

The first line contains the integers NN and KK. (1KN50001 \le K \le N \le 5\,000) NN is divisible by KK.

The second line contains NN space separated integers v1,v2,,vNv_1, v_2, \dots, v_N. (1vi1091 \le v_i \le 10^9) The value viv_i is the skill of the ii-th student in the queue.

All students have distinct skills.

Output

Print the minimum number of minutes on the first and only line.

Hint

In the sample with six students and KK equal to 3, Ante moves the students with skills 5, 6 and 3 to the front of the queue. That takes him three minutes.