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>
using namespace std;
const long double EPS = 1e-14;
const long long maxn = 200500;
const long long mod = 1e9 + 7;
vector<pair<long long, long long> > v;
long long cntp[maxn], cnts[maxn], costp[maxn], costs[maxn];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (auto &x : a) cin >> x;
  sort((a).begin(), (a).end());
  for (long long i = 0; i < n; ++i) {
    long long j = i;
    while (j < n && a[j] == a[i]) ++j;
    v.push_back({a[i], j - i});
    i = j - 1;
  }
  n = (long long)(v).size();
  cntp[0] = v[0].second;
  cnts[n - 1] = v[n - 1].second;
  for (long long i = 1; i < n; ++i) {
    cntp[i] = cntp[i - 1] + v[i].second;
    costp[i] = costp[i - 1] + cntp[i - 1] * (v[i].first - v[i - 1].first);
  }
  for (long long i = n - 2; i >= 0; --i) {
    cnts[i] = v[i].second + cnts[i + 1];
    costs[i] = costs[i + 1] + cnts[i + 1] * (v[i + 1].first - v[i].first);
  }
  long long ans = 1e18;
  for (long long i = 0; i < n; ++i) {
    long long adp = (i ? cntp[i - 1] : 0), smp = (i ? costp[i - 1] : 0);
    long long ads = cnts[i + 1], sms = costs[i + 1];
    long long need = k - v[i].second;
    if (adp) smp += adp * (v[i].first - 1 - v[i - 1].first);
    if (ads) sms += ads * (v[i + 1].first - v[i].first - 1);
    if (need <= 0) {
      ans = 0;
      break;
    }
    long long tm = 1e18;
    if (adp >= need) tm = smp + need;
    if (ads >= need) tm = min(tm, sms + need);
    if (ads < need && adp < need && ads + adp >= need) {
      long long tmp = sms + smp;
      if ((v[i].first - v[i - 1].first) < (v[i + 1].first - v[i].first)) {
        tmp += adp;
        need -= adp;
        tmp += need;
      } else {
        tmp += ads;
        need -= ads;
        tmp += need;
      }
      tm = min(tm, tmp);
    }
    ans = min(ans, tm);
  }
  cout << ans << '\n';
  return 0;
}
