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 optimize GCC("O3")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n);
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  sort(a.begin(), a.end());
  long long i = 0;
  map<long long, long long> pfc;
  pfc[a[i]] = 0;
  map<long long, long long> pfs;
  pfs[a[i]] = 0;
  vector<pair<long long, long long> > v;
  for (pair<long long, long long> p : m) {
    v.push_back(p);
    while (p.first != a[i]) i++;
    if (i == 0) continue;
    pfc[a[i]] = pfc[a[i - 1]] + m[a[i - 1]];
    pfs[a[i]] = pfs[a[i - 1]] + a[i - 1] * m[a[i - 1]];
  }
  reverse(v.begin(), v.end());
  i = n - 1;
  map<long long, long long> sfc;
  sfc[a[i]] = 0;
  map<long long, long long> sfs;
  sfs[a[i]] = 0;
  for (pair<long long, long long> p : v) {
    while (p.first != a[i]) i--;
    if (i == n - 1) continue;
    sfc[a[i]] = sfc[a[i + 1]] + m[a[i + 1]];
    sfs[a[i]] = sfs[a[i + 1]] + a[i + 1] * m[a[i + 1]];
  }
  long long ans = 1e18;
  for (int i = 0; i < v.size(); i++) {
    long long ne = max(0ll, k - v[i].second);
    if (ne == 0) {
      ans = 0ll;
      break;
    }
    long long nel = min(ne, pfc[v[i].first]);
    long long ner = ne - nel;
    long long lsum = (v[i].first - 1) * pfc[v[i].first] - pfs[v[i].first] + nel;
    long long rsum = 0;
    if (ner > 0)
      rsum = sfs[v[i].first] - (v[i].first + 1) * sfc[v[i].first] + ner;
    ans = min(ans, lsum + rsum);
    ner = min(ne, sfc[v[i].first]);
    nel = ne - ner;
    rsum = sfs[v[i].first] - (v[i].first + 1) * sfc[v[i].first] + ner;
    if (nel > 0)
      lsum = (v[i].first - 1) * pfc[v[i].first] - pfs[v[i].first] + nel;
    else
      lsum = 0;
    ans = min(ans, lsum + rsum);
  }
  cout << ans << endl;
  return 0;
}
