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 double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const long long MOD = 1e9 + 7;
inline long long __min(long long a, long long b) {
  return (a == -1 || b == -1) ? (a + b + 1) : (min(a, b));
}
long long valf(long long val, int k, long long cum_suml, long long cum_sumr,
               int num_l, int num_r) {
  if (k <= 0) return 0ll;
  long long ans = -1;
  if (num_l >= k) {
    ans = __min(ans, (val - 1) * num_l - cum_suml + k);
  }
  if (num_r >= k) {
    ans = __min(ans, cum_sumr - (val + 1) * num_r + k);
  }
  ans = __min(ans,
              cum_sumr - (val + 1) * num_r + (val - 1) * num_l - cum_suml + k);
  return ans;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<long long> a(n, 0ll);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int cnt_dist = 0;
  vector<long long> dist_elements, sum_cum;
  vector<int> number_of_elements;
  long long tot_sum = 0;
  for (int i = 0; i < n; i++) {
    tot_sum += a[i];
    if (cnt_dist > 0 && dist_elements[cnt_dist - 1] == a[i]) {
      sum_cum[cnt_dist - 1] += a[i];
      number_of_elements[cnt_dist - 1]++;
    } else {
      dist_elements.push_back(a[i]);
      sum_cum.push_back(a[i]);
      number_of_elements.push_back(1);
      cnt_dist++;
    }
  }
  long long ans = -1, sum_so_far = 0;
  long long l, r, mid, v1, v2, v3;
  int ele_so_far = 0;
  cnt_dist = dist_elements.size();
  for (int i = 0; i < cnt_dist; i++) {
    ans = __min(ans, valf(dist_elements[i], k - number_of_elements[i],
                          sum_so_far, tot_sum - sum_cum[i] - sum_so_far,
                          ele_so_far, n - ele_so_far - number_of_elements[i]));
    if (i > 0 && dist_elements[i] - dist_elements[i - 1] > 1) {
      l = dist_elements[i - 1] + 1;
      r = dist_elements[i] - 1;
      while (r - l > 1) {
        mid = (l + r) / 2;
        v1 = valf(mid - 1, k, sum_so_far, tot_sum - sum_so_far, ele_so_far,
                  n - ele_so_far);
        v2 = valf(mid, k, sum_so_far, tot_sum - sum_so_far, ele_so_far,
                  n - ele_so_far);
        v3 = valf(mid + 1, k, sum_so_far, tot_sum - sum_so_far, ele_so_far,
                  n - ele_so_far);
        if (v1 >= v2 && v2 >= v3) {
          l = mid;
        } else {
          r = mid;
        }
      }
      v1 = valf(l, k, sum_so_far, tot_sum - sum_so_far, ele_so_far,
                n - ele_so_far);
      v2 = valf(r, k, sum_so_far, tot_sum - sum_so_far, ele_so_far,
                n - ele_so_far);
      ans = __min(ans, __min(v1, v2));
    }
    sum_so_far += sum_cum[i];
    ele_so_far += number_of_elements[i];
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  solve();
  return 0;
}
