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;
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  map<long long int, long long int> bag;
  for (long long int i = 0; i < n; i++) bag[v[i]]++;
  vector<pair<long long int, long long int> > vpll;
  vpll.push_back(pair<long long int, long long int>(0, 0));
  for (auto it = bag.begin(); it != bag.end(); ++it) {
    vpll.push_back(pair<long long int, long long int>(it->first, it->second));
  }
  vpll.push_back(pair<long long int, long long int>(1e18, 0));
  sort(vpll.begin(), vpll.end());
  vector<long long int> costL(vpll.size() + 2, 0), costR(vpll.size() + 2, 0);
  vector<long long int> countL(vpll.size() + 2, 0), countR(vpll.size() + 2, 0);
  for (int i = 1; i < vpll.size() - 1; i++) {
    int index = i;
    countL[index + 1] = countL[index] + vpll[index].second;
    costL[index] =
        costL[index - 1] +
        countL[index] * abs(vpll[index].first - vpll[index - 1].first);
  }
  for (int i = 1; i < vpll.size() - 1; i++) {
    int index = vpll.size() - i;
    countR[index - 1] = countR[index] + vpll[index].second;
    costR[index] =
        costR[index + 1] +
        countR[index] * abs(vpll[index].first - vpll[index + 1].first);
  }
  long long int ans = 1e18;
  for (int i = 1; i < vpll.size() - 1; i++) {
    long long int qtyA = countL[i];
    long long int qtyB = countR[i];
    long long int cA = costL[i - 1];
    long long int cB = costR[i + 1];
    long long int diffA = abs(vpll[i].first - vpll[i - 1].first);
    long long int diffB = abs(vpll[i].first - vpll[i + 1].first);
    for (int j = 0; j < 2; j++) {
      long long int tmp = 0;
      long long int req = max(0ll, k - vpll[i].second);
      long long int rmA = min(qtyA, req);
      long long int rmB = req - rmA;
      if (rmA) tmp += cA + rmA + (diffA - 1ll) * qtyA;
      if (rmB) tmp += cB + rmB + (diffB - 1ll) * qtyB;
      swap(qtyA, qtyB);
      swap(cA, cB);
      swap(diffA, diffB);
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
}
