We’re preparing your current view and syncing the latest data.
You are given n barrels with certain amounts of liquid. You want k of them to have the same amount of liquid. The only allowed operation is to pour liquid from one barrel to another, where the receiving barrel's amount increases and the pouring barrel's amount stays the same. Find the minimum number of such operations required to make at least k barrels have identical volume.
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50), the number of barrels and the number needed to have equal amounts. The second line contains n integers a_i (1 ≤ a_i ≤ 10^4), where a_i is the amount of liquid in the i-th barrel.
Print the minimum number of pouring operations needed to ensure that at least k barrels have the same amount of liquid.
1 ≤ k ≤ n ≤ 50; 1 ≤ a_i ≤ 10^4
Example 1
Input
4 3 2 3 2 4
Output
1
Explanation
To have at least 3 barrels with equal amount, choose amount 2 (since there are already two barrels with 2). Pour the third barrel with 3 into one of the barrels with 2, one operation.