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;
using ll = long long;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return 0;
}
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
vector<P> runLength(const vector<ll>& A) {
  vector<P> res;
  ll now = A[0];
  ll cnt = 1;
  for (int i = (int)1; i < (int)A.size(); ++i) {
    if (A[i] == now) {
      ++cnt;
    } else {
      res.emplace_back(now, cnt);
      now = A[i];
      cnt = 1;
    }
  }
  res.emplace_back(now, cnt);
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (auto& a : A) {
    cin >> a;
  }
  sort((A).begin(), (A).end());
  vector<P> B = runLength(A);
  int M = (int)B.size();
  vector<ll> head_cumsum(M + 2, 0), tail_cumsum(M + 2, 0);
  vector<ll> head_cnt(M + 2, 0), tail_cnt(M + 2, 0);
  for (int i = (int)0; i < (int)M; ++i) {
    head_cumsum[i + 1] = head_cumsum[i] + B[i].first * B[i].second;
    head_cnt[i + 1] = head_cnt[i] + B[i].second;
  }
  for (int i = (int)M - 1; i >= (int)0; --i) {
    tail_cumsum[i + 1] = tail_cumsum[i + 2] + B[i].first * B[i].second;
    tail_cnt[i + 1] = tail_cnt[i + 2] + B[i].second;
  }
  ll ans = INF;
  for (int i = (int)1; i < (int)M + 1; ++i) {
    if (B[i - 1].second >= K) {
      cout << 0 << endl;
      return 0;
    }
    ll head_cost = (B[i - 1].first - 1) * head_cnt[i - 1] - head_cumsum[i - 1];
    ll tail_cost = tail_cumsum[i + 1] - (B[i - 1].first + 1) * tail_cnt[i + 1];
    ll rest = K - B[i - 1].second;
    ll head_rest = head_cnt[i - 1];
    ll tail_rest = tail_cnt[i + 1];
    {
      ll now_ans = head_cost;
      ll now_rest = rest;
      ll cnt = min(now_rest, head_rest);
      now_ans += cnt;
      now_rest -= cnt;
      if (now_rest) {
        now_ans += tail_cost + now_rest;
      }
      chmin(ans, now_ans);
    }
    {
      ll now_ans = tail_cost;
      ll now_rest = rest;
      ll cnt = min(now_rest, tail_rest);
      now_ans += cnt;
      now_rest -= cnt;
      if (now_rest) {
        now_ans += head_cost + now_rest;
      }
      chmin(ans, now_ans);
    }
  }
  cout << ans << endl;
  return 0;
}