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;
template <typename T1>
void dbg_pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
  cout << "{";
  if (start < 0) start = 0;
  if (end < 0) end = V.size() - 1;
  for (int i = start; i <= end; i++) {
    cout << V[i] + add << ((i == end) ? "}" : " ");
  }
}
void dbg_pr(string V) { cout << "\"" << V << "\""; }
template <typename T1>
void dbg_pr(T1 V) {
  cout << V;
}
template <typename T1, typename T2>
void dbg_pr(map<T1, T2> M) {
  cout << "{";
  for (const auto m : M) {
    dbg_pr(m.first);
    cout << ":";
    dbg_pr(m.second);
    cout << ",";
  }
  cout << "}";
}
void debug_out() { cout << "\033[0m\n"; }
template <typename T1, typename... T2>
void debug_out(T1 A, T2... B) {
  cout << " ";
  dbg_pr(A);
  debug_out(B...);
}
int test = 1;
void setupFastCin() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
template <typename T1>
T1 chmin(T1 &x, const T1 v) {
  return x = min(x, v);
}
template <typename T1>
T1 chmax(T1 &x, const T1 v) {
  return x = max(x, v);
}
template <typename T1>
void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
  if (start < 0) start = 0;
  if (end < 0) end = V.size() - 1;
  for (int i = start; i <= end; i++) {
    cout << V[i] + add << ((i == end) ? "\n" : " ");
  }
}
template <typename T1>
T1 gcd(const T1 &a, const T1 &b) {
  if (a == 0 || b == 0) return a + b;
  return gcd(b, a % b);
}
const int MAX = 200005;
const long long MOD = 998244353ll;
long long calc(vector<pair<long long, long long> > N, const int k) {
  if (N[0].second >= k) return 0;
  long long c = 0;
  for (int i = 1; i < N.size(); i++) {
    N[i].second += N[i - 1].second;
    c += N[i - 1].second * abs(N[i].first - N[i - 1].first);
    if (N[i].second >= k) {
      long long rm = min(N[i].second - k, N[i - 1].second);
      return c - rm;
    }
  }
  assert(0);
  return -1;
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<long long> N(n), S(n);
  for (int i = 0; i < n; i++) cin >> N[i];
  sort(N.begin(), N.end());
  vector<pair<long long, long long> > P;
  for (int i = 0; i < n; i++) {
    if (P.size() == 0 || N[i] != P.back().first) P.push_back({N[i], 0});
    P.back().second++;
    if (P.back().second >= k) {
      cout << 0 << "\n";
      return;
    };
  }
  long long b = 0;
  int m = (n - 1) / 2;
  for (int i = 0; i < n; i++) {
    b += abs(N[i] - N[m]);
  }
  1337;
  b += (k - n);
  chmin(b, calc(P, k));
  reverse(P.begin(), P.end());
  chmin(b, calc(P, k));
  {
    cout << b << "\n";
    return;
  };
}
int main() {
  setupFastCin();
  int t = 1;
  while (t--) solve();
  return 0;
}