The annual table tennis team competition for students of the University of Zagreb takes place next Saturday. Each team consists of K students, and N 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 K students in the queue form the first team, the next K students form the second team, the next K students form the third team, and so on. N is divisible by K, so no student is left without a team.
Ante has rated the skill of every student with one integer. He wants the K weakest students in the first team, the next K weakest in the second team, the next K 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.
The first line contains the integers N and K. (1≤K≤N≤5000) N is divisible by K.
The second line contains N space separated integers v1,v2,…,vN. (1≤vi≤109) The value vi is the skill of the i-th student in the queue.
All students have distinct skills.
Print the minimum number of minutes on the first and only line.
In the sample with six students and K equal to 3, Ante moves the students with skills 5, 6 and 3 to the front of the queue. That takes him three minutes.