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 GCD(long long x, long long y) {
  if (y == 0) return x;
  if (x > y) return GCD(y, x % y);
  return GCD(x, y % x);
}
long long LCM(long long x, long long y) { return (x * y) / GCD(x, y); }
long long MPOW(long long a, long long b, long long m = LLONG_MAX) {
  if (b == 0) return 1;
  if (b & 1) return ((a % m) * (MPOW(a, b - 1, m) % m)) % m;
  a = (a * a) % m;
  return (MPOW(a, b / 2, m));
}
long long MINV(long long a, long long m) { return MPOW(a, m - 2, m); }
inline bool max3(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
inline bool min3(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
inline bool sortbythis(pair<int, int> a, pair<int, int> b) {
  return ((a.first == b.first && a.second < b.second) || (a.first < b.first));
}
inline bool sortbythat(pair<int, int> a, pair<int, int> b) {
  return ((a.second == b.second && a.first < b.first) || (a.second < b.second));
}
class pnc {
  long long FACTMAX, MODU;
  vector<long long> fact;

 public:
  pnc(long long n, long long m) {
    FACTMAX = n;
    MODU = m;
    fact.resize(n + 1);
    MFACT_INIT(MODU);
  }
  void MFACT_INIT(long long m) {
    fact[0] = 1;
    for (int i = 1; i <= FACTMAX; i++) fact[i] = (i * fact[i - 1]) % MODU;
  }
  long long MFACT(long long n) { return fact[n]; }
  long long PERM(long long n, long long r) {
    return (fact[n] * MINV(fact[n - r], MODU)) % MODU;
  }
  long long COMB(long long n, long long r) {
    return (PERM(n, r) * MINV(fact[r], MODU)) % MODU;
  }
};
const int MAXN = int(1e5);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  map<int, vector<int> > M;
  int(n), (k);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int(a);
    cin >> a;
    int cnt = 0;
    while (a) {
      if (M.find(a) == M.end())
        M[a] = vector<int>(1, cnt);
      else
        M[a].push_back(cnt);
      cnt++;
      a = (a / 2);
    }
    if (M.find(0) == M.end())
      M[0] = vector<int>(1, cnt);
    else
      M[0].push_back(cnt);
  }
  int ans = (int)(1000000007);
  for (auto& it : M) {
    if ((it.second).size() >= k) {
      sort((it.second).begin(), (it.second).end());
      int temp = 0;
      for (int i = 0; i <= k - 1; i++) {
        temp += (it.second)[i];
      }
      ans = min(temp, ans);
    }
  }
  cout << ans;
  return 0;
}
