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
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = INT_MAX;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int mul(int x, int y) {
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p = clock();
long long pref[N];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i <= n - 1; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  pref[0] = a[0];
  for (int i = 1; i <= n - 1; ++i) pref[i] = a[i] + pref[i - 1];
  long long ans = 1e18;
  for (int i = 0; i <= n - 1; ++i) {
    int get = a[i];
    int n1 = lower_bound(a.begin(), a.end(), get - 1) - a.begin();
    int n2 = a.end() - upper_bound(a.begin(), a.end(), get + 1);
    int n3 = upper_bound(a.begin(), a.end(), get - 1) -
             lower_bound(a.begin(), a.end(), get - 1);
    int n4 = upper_bound(a.begin(), a.end(), get) -
             lower_bound(a.begin(), a.end(), get);
    int n5 = upper_bound(a.begin(), a.end(), get + 1) -
             lower_bound(a.begin(), a.end(), get + 1);
    long long c1 = n1 * 1LL * (get - 1) - (n1 == 0 ? 0 : pref[n1 - 1]);
    long long c2 =
        (pref[n - 1] - (n2 == n ? 0 : pref[n - 1 - n2])) - n2 * 1LL * (get + 1);
    ;
    if (n4 >= k) {
      ans = 0;
      break;
    }
    if (n1 + n3 >= k - n4) {
      ans = min(ans, c1 + k - n4);
    }
    if (n2 + n5 >= k - n4) {
      ans = min(ans, c2 + k - n4);
    }
    if (n1 + n3 + n2 + n5 >= k - n4) {
      ans = min(ans, c1 + c2 + k - n4);
    }
  }
  cout << ans << "\n";
  time_p = clock() - time_p;
  cerr << "\nTime Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
  return 0;
}
