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;
long long MOD;
long long exp(long long a, long long n) {
  if (n == 0) return 1;
  long long result = a, residue = 1;
  while (n > 1LL) {
    if (n % 2LL == 1LL) residue = residue * result % MOD;
    result = result * result % MOD;
    n = (n >> 1LL);
  }
  return result * residue % MOD;
}
void extended(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return;
  }
  extended(b % a, a, x, y);
  long long temp = y;
  y = x;
  x = temp - (b / a) * x;
}
int rs(long long a) {
  int val = 0;
  while (a > 0LL) {
    a = (a >> 1LL);
    val++;
  }
  return val;
}
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(200001, 0), presum(200002, 0), sufsum(200002, 0);
  map<long long, long long> f;
  long long ans = 4000000000000000LL, temp = 0, fact;
  for (int i = 1; i <= n; i++) cin >> a[i], f[a[i]]++;
  sort(a.begin() + 1, a.begin() + n + 1);
  for (int i = 1; i <= n; i++) presum[i] = presum[i - 1] + a[i];
  for (int i = n; i > 0; i--) sufsum[i] = sufsum[i + 1] + a[i];
  for (long long i = 1; i <= n; i++) {
    long long val = a[i];
    long long req = max(0LL, k - f[a[i]]);
    long long lefttemp = 0;
    if (req > 0)
      lefttemp = (i - 1) * (val - 1) - presum[i - 1] + min(req, i - 1);
    req -= min(req, i - 1);
    if (req > 0)
      lefttemp += sufsum[i + f[a[i]]] - (n - i - f[a[i]] + 1) * (val + 1) + req;
    ans = min(ans, lefttemp);
    req = max(0LL, k - f[a[i]]);
    long long righttemp = 0;
    if (req > 0)
      righttemp = sufsum[i + f[a[i]]] - (n - i - f[a[i]] + 1) * (val + 1) +
                  min(req, n - i - f[a[i]] + 1);
    req -= min(req, n - i - f[a[i]] + 1);
    if (req > 0) righttemp += (i - 1) * (val - 1) - presum[i - 1] + req;
    ans = min(ans, righttemp);
    i += f[a[i]] - 1;
  }
  cout << ans << endl;
  return 0;
}