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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int arr[n];
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  sort(arr, arr + n);
  vector<pair<long long int, long long int>> segs;
  for (long long int i = 0; i < n;) {
    long long int size = 1;
    long long int j = i + 1;
    while (j < n && arr[j] == arr[i]) {
      size++;
      j++;
    }
    segs.push_back({arr[i], size});
    if (size >= k) {
      cout << 0;
      return;
    }
    i = j;
  }
  long long int size = segs.size();
  long long int pref[size], suff[size];
  long long int cost_left[size + 1], cost_right[size + 1];
  long long int curr_size = 0;
  for (long long int i = 0; i < size; i++) {
    curr_size += segs[i].second;
    pref[i] = curr_size;
  }
  curr_size = 0;
  for (long long int i = size - 1; i >= 0; i--) {
    curr_size += segs[i].second;
    suff[i] = curr_size;
  }
  long long int cost = 0;
  for (long long int i = 0; i < size - 1; i++) {
    cost += pref[i] * (segs[i + 1].first - segs[i].first);
    cost_left[i] = cost;
  }
  cost = 0;
  for (long long int i = size - 2; i >= 0; i--) {
    cost += suff[i + 1] * (segs[i + 1].first - segs[i].first);
    cost_right[i + 1] = cost;
  }
  long long int ans = 1e15;
  for (long long int i = 0; i < size; i++) {
    if (i == 0) {
      cost = cost_right[1] - suff[1];
      long long int have = segs[i].second;
      long long int need = max(0LL, k - have);
      cost = cost + need;
      ans = min(ans, cost);
    } else if (i == size - 1) {
      cost = cost_left[size - 2] - pref[size - 2];
      long long int have = segs[i].second;
      long long int need = max(0LL, k - have);
      cost = cost + need;
      ans = min(ans, cost);
    } else {
      long long int cost1 = cost_left[i - 1] - pref[i - 1];
      long long int cost2 = cost_right[i + 1] - suff[i + 1];
      long long int have = segs[i].second;
      long long int need = max(0LL, k - have);
      long long int ans1 = 1e15, ans2 = 1e15;
      long long int temp1 = cost1, temp2 = cost2;
      temp1 += min(need, pref[i - 1]);
      need = max(0LL, need - pref[i - 1]);
      if (need > 0) {
        temp1 += temp2 + need;
      }
      ans1 = temp1;
      need = max(0LL, k - have);
      cost2 += min(need, suff[i + 1]);
      need = max(0LL, need - suff[i + 1]);
      if (need > 0) cost2 += cost1 + need;
      ans2 = cost2;
      ans = min({ans, ans1, ans2});
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}