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
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 10;
struct Node {
  long long val, num;
} node[MAXN];
long long precnt[MAXN], sufcnt[MAXN];
long long presum[MAXN], sufsum[MAXN];
long long val[MAXN];
int main() {
  long long n, k;
  scanf("%lld %lld", &n, &k);
  for (long long i = 1; i <= n; i++) scanf("%lld", &val[i]);
  long long num = 1;
  sort(val + 1, val + n + 1);
  node[1].val = val[1];
  node[1].num = 1;
  for (long long i = 2; i <= n; i++) {
    if (val[i] != val[i - 1]) {
      node[++num].val = val[i];
      node[num].num = 1;
    } else {
      node[num].num++;
    }
  }
  for (long long i = 1; i <= num; i++) {
    precnt[i] = precnt[i - 1] + node[i].num;
    presum[i] = presum[i - 1] + node[i].num * node[i].val;
  }
  for (long long i = num; i >= 1; i--) {
    sufcnt[i] = sufcnt[i + 1] + node[i].num;
    sufsum[i] = sufsum[i + 1] + node[i].num * node[i].val;
  }
  long long res = 1e18;
  for (long long i = 1; i <= num; i++) {
    long long need = max((long long)0, k - node[i].num);
    long long needl = min(need, precnt[i - 1]);
    long long needr = max((long long)0, need - needl);
    long long mvl =
        needl ? (needl + (node[i].val - 1) * precnt[i - 1] - presum[i - 1]) : 0;
    long long mvr =
        needr ? (needr + sufsum[i + 1] - (node[i].val + 1) * sufcnt[i + 1]) : 0;
    res = min(res, mvl + mvr);
  }
  for (long long i = num; i >= 1; i--) {
    long long need = max((long long)0, k - node[i].num);
    long long needr = min(need, sufcnt[i + 1]);
    long long needl = max((long long)0, need - needr);
    long long mvr =
        needr ? (needr + sufsum[i + 1] - (node[i].val + 1) * sufcnt[i + 1]) : 0;
    long long mvl =
        needl ? (needl + (node[i].val - 1) * precnt[i - 1] - presum[i - 1]) : 0;
    res = min(res, mvl + mvr);
  }
  printf("%lld\n", res);
  return 0;
}
