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;
void run() {
  long long n, k;
  cin >> n >> k;
  vector<long long> value(n), prefix_count;
  vector<long long> prefix_sum;
  vector<pair<long long, long long>> extract;
  map<long long, long long> cnt;
  for (auto &i : value) {
    cin >> i;
    cnt[i]++;
  }
  for (auto &i : cnt) extract.emplace_back(i);
  sort(value.begin(), value.end());
  prefix_count.resize(extract.size());
  prefix_sum.resize(extract.size());
  for (long long i = 0; i < extract.size(); i++) {
    prefix_sum[i] = 1LL * extract[i].first * extract[i].second +
                    (i ? prefix_sum[i - 1] : 0);
    prefix_count[i] = extract[i].second + (i ? prefix_count[i - 1] : 0);
  }
  long long ans = 1e17;
  for (long long i = 0; i < extract.size(); i++) {
    long long temp = 0;
    long long current_k = k - extract[i].second;
    if (current_k <= 0) {
      ans = 0;
      continue;
    }
    if (prefix_count[i] >= k) {
      temp = 0;
      current_k = k - extract[i].second;
      temp += 1LL * (i ? prefix_count[i - 1] : 0) * (extract[i].first - 1);
      temp -= (i ? prefix_sum[i - 1] : 0);
      temp += current_k;
      ans = min(ans, temp);
    }
    if (prefix_count.back() - (i ? prefix_count[i - 1] : 0) >= k) {
      temp = 0;
      current_k = k - extract[i].second;
      temp += prefix_sum.back() - prefix_sum[i];
      temp -= 1LL * (prefix_count.back() - prefix_count[i]) *
              (extract[i].first + 1);
      temp += current_k;
      ans = min(ans, temp);
    }
    temp = 0;
    current_k = k - extract[i].second;
    temp += prefix_sum.back() - prefix_sum[i];
    temp -=
        1LL * (prefix_count.back() - prefix_count[i]) * (extract[i].first + 1);
    auto delta = min(current_k, n - 1 - i);
    temp += delta;
    current_k -= delta;
    temp += 1LL * (i ? prefix_count[i - 1] : 0) * (extract[i].first - 1);
    temp -= (i ? prefix_sum[i - 1] : 0);
    delta = min(current_k, i);
    temp += delta;
    current_k -= delta;
    assert(current_k == 0);
    ans = min(ans, temp);
  }
  assert(ans != 1e17);
  cout << ans;
}
signed main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  run();
  return 0;
}