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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long i, j, k, m, n, q, r, c, t;
  cin >> n >> k;
  map<long long, long long> make_pair;
  for (long long(i) = (0); (i) < (n); ++(i)) {
    cin >> j;
    make_pair[j]++;
  }
  n = make_pair.size();
  vector<long long> le(n + 2, 0), re(n + 2, 0), lc(n + 2, 0), rc(n + 2, 0);
  auto it = make_pair.begin();
  i = 2;
  le[1] = it->second;
  j = it->first;
  ++it;
  vector<long long> cu(n + 2, 0);
  cu[1] = le[1];
  for (; it != make_pair.end(); ++it) {
    cu[i] = it->second;
    le[i] = le[i - 1] + it->second;
    lc[i] = le[i - 1] * (it->first - j) + lc[i - 1];
    i++;
    j = it->first;
  }
  auto itt = make_pair.rbegin();
  i = n - 1;
  re[n] = itt->second;
  j = itt->first;
  ++itt;
  for (; itt != make_pair.rend(); ++itt) {
    re[i] = re[i + 1] + itt->second;
    rc[i] = re[i + 1] * (j - itt->first) + rc[i + 1];
    i--;
    j = itt->first;
  }
  long long ans = 1e18;
  long long left, right, sum, kk;
  for (i = 2; i <= n - 1; i++) {
    if (cu[i] >= k) {
      cout << "0";
      return 0;
    }
    kk = k - cu[i];
    if (le[i - 1] < kk && re[i + 1] < kk) {
      j = kk - le[i - 1];
      sum = lc[i];
      sum += rc[i] - (re[i + 1] - j);
      ans = min(ans, sum);
      j = kk - re[i + 1];
      sum = rc[i];
      sum += lc[i] - (le[i - 1] - j);
      ans = min(ans, sum);
    } else {
      if (le[i - 1] >= kk) {
        left = lc[i] - (le[i - 1] - kk);
        ans = min(ans, left);
      }
      if (re[i + 1] >= kk) {
        right = rc[i] - (re[i + 1] - kk);
        ans = min(ans, right);
      }
    }
  }
  if (cu[1] >= k) {
    cout << "0";
    return 0;
  }
  kk = k - cu[1];
  ans = min(ans, rc[1] - (re[2] - kk));
  if (cu[n] >= k) {
    cout << "0";
    return 0;
  }
  kk = k - cu[n];
  ans = min(ans, lc[n] - (le[n - 1] - kk));
  cout << ans;
}