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;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2 != 0) {
      ans = (ans * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n == 1 || k == 1) {
      cout << 0;
      return 0;
    }
    sort(a, a + n);
    map<long long, long long> m;
    for (int i = 0; i < n; i++) {
      m[a[i]]++;
    }
    long long mi = 1e18;
    vector<pair<long long, long long>> v;
    for (auto i : m) v.push_back(i);
    long long b1[v.size()], b2[v.size()];
    long long count1[v.size()], count2[v.size()];
    b1[0] = 0;
    long long cnt = 0;
    for (int i = 0; i < v.size(); i++) {
      if (i == 0)
        b1[i] = 0;
      else
        b1[i] = cnt * (v[i].first - v[i - 1].first) + b1[i - 1];
      cnt += v[i].second;
      count1[i] = cnt;
    }
    b2[v.size() - 1] = 0;
    cnt = 0;
    for (int i = v.size() - 1; i >= 0; i--) {
      if (i == v.size() - 1)
        b2[i] = 0;
      else
        b2[i] = cnt * (v[i + 1].first - v[i].first) + b2[i + 1];
      cnt += v[i].second;
      count2[i] = cnt;
    }
    for (int i = 1; i < v.size() - 1; i++) {
      long long val = v[i].first;
      cnt = k - v[i].second;
      if (cnt <= 0) {
        mi = 0;
        break;
      }
      long long left = val - 1, right = val + 1;
      left = left - v[i - 1].first;
      right = v[i + 1].first - right;
      long long p = left * count1[i - 1] + b1[i - 1],
                q = right * count2[i + 1] + b2[i + 1];
      long long ha = cnt + p;
      long long o = min(count1[i - 1], cnt);
      if (cnt - o != 0) ha += q;
      mi = min(mi, ha);
      ha = cnt + q;
      o = min(count2[i + 1], cnt);
      if (cnt - o != 0) ha += p;
      mi = min(mi, ha);
    }
    long long val = v[0].first;
    cnt = k - v[0].second;
    if (cnt <= 0) {
      mi = 0;
    } else {
      long long right = val + 1;
      right = v[1].first - right;
      long long q = right * count2[1] + b2[1];
      mi = min(mi, cnt + q);
    }
    val = v[v.size() - 1].first;
    cnt = k - v[v.size() - 1].second;
    if (cnt <= 0) {
      mi = 0;
    } else {
      long long left = val - 1;
      left = left - v[v.size() - 2].first;
      long long q = left * count1[v.size() - 2] + b1[v.size() - 2];
      mi = min(mi, cnt + q);
    }
    cout << mi;
  }
  return 0;
}
