Problem: You are given the array a consisting of n elements and the integer k ≤ n.

You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations:

  * Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum value of a is mn then you choose such index i that a_i = mn and set a_i := a_i + 1); 
  * take one of the maximum elements of the array and decrease its value by one (more formally, if the maximum value of a is mx then you choose such index i that a_i = mx and set a_i := a_i - 1). 



Your task is to calculate the minimum number of moves required to obtain at least k equal elements in the array.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a and the required number of equal elements.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the i-th element of a.

Output

Print one integer — the minimum number of moves required to obtain at least k equal elements in the array.

Examples

Input


6 5
1 2 2 4 2 3


Output


3


Input


7 5
3 3 2 1 1 1 3


Output


4

Solution (in JAVA):

Solution:
function solve(nums, k, n) {
    if (k === 0) return 0

    nums.sort(function (a, b) {
        return a - b
    })

    for(var i = 0; i + k - 1 < n; i++) {
        if(nums[i] === nums[i + k - 1]) {
            return 0
        }
    }

    var lcost = 0, rcost = 0

    for(var i = 0; i < k; i++) {
        lcost += nums[k - 1] - nums[i]
        rcost += nums[n - 1 - i] - nums[n - k]
    }

    for(var j = k; j < n; j++) {
        if(nums[k - 1] === nums[j]) lcost--
        if(nums[n - k] === nums[n - j - 1]) rcost--
    }

    var sum = 0
    for(var i = 0; i < n - 1 - i; i++) {
        sum += nums[n - 1 - i] - nums[i]
    }

    //console.log(sum, lcost, rcost)

    return Math.min(sum - (n - k), lcost, rcost)
}



// const arr1 = [1, 2, 3, 4, 5]
// console.log(solve(arr1, 5, 5) === 6)
// // const arr10 = [1, 2, 3, 4, 5, 6]
// // console.log(solve(arr10, 6))
// //
// const arr2 = [1, 1, 1, 2, 5]
// console.log(solve(arr2, 4, 5) === 3)
// // // //
// const arr32 = [1, 1, 1, 2, 2]
// console.log(solve(arr32, 3, 5) === 0)
// //
// // //
//
// const arr4 = Array.from({length: 200000}, (_, index) => ++index)
// console.log(solve(arr4, 200000, 200000) === 10000000000)
// // // // //
// const arr5 = [1, 2, 2, 4, 2, 3]
// console.log(solve(arr5, 5, 6) === 3)
// // // //
// const arr6 = [1, 1, 1, 2, 3, 3, 3]
// console.log(solve(arr6, 5, 7))
//
// const arr = [1285, 1286, 1288, 1288, 1289, 1290, 1292, 1292, 1293, 1294, 1294, 1296, 2000, 2273, 2275, 2275, 2277, 2278, 2278, 2278, 2280, 2280, 2285]
// console.log(solve(arr, 10) === 42)
//
// const arr8 = [1, 123]
// console.log(solve(arr8, 2) === 122)

var line1 = readline().split(" ")
var k = Number(line1[1])
var n = Number(line1[0])
var nums = readline().split(" ").map(function(x) {return Number(x)})
print(solve(nums, k, n))