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 T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) {
    if (vi != v.begin()) os << ", ";
    os << *vi;
  }
  os << "}";
  return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
const long long LL_INF = (long long)2e18 + 5;
int N, K;
vector<int> A;
vector<long long> prefix_sum, suffix_sum;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  A.resize(N);
  for (int &a : A) cin >> a;
  sort(A.begin(), A.end());
  prefix_sum.assign(N + 1, 0);
  suffix_sum.assign(N + 1, 0);
  for (int i = 0; i < N; i++) prefix_sum[i + 1] = prefix_sum[i] + A[i];
  for (int i = N - 1; i >= 0; i--) suffix_sum[i] = suffix_sum[i + 1] + A[i];
  long long answer = LL_INF;
  for (int i = 0, j = 0; i < N; i = j) {
    long long value = A[i];
    while (j < N && A[j] == value) j++;
    if (j - i >= K) {
      answer = 0;
      break;
    }
    int need = K - (j - i);
    int before = i;
    int after = N - j;
    long long before_cost = before * value - prefix_sum[i];
    long long after_cost = suffix_sum[j] - after * value;
    if (before >= need) answer = min(answer, before_cost - (before - need));
    if (after >= need) answer = min(answer, after_cost - (after - need));
    answer = min(answer, before_cost + after_cost - (before + after - need));
  }
  cout << answer << '\n';
}