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>
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
long long mod = 1000000007;
using namespace std;
bool isPrime(long long n) {
  long long j;
  for (j = 2; j <= sqrt(n); j++) {
    if (n % j == 0) {
      break;
    }
  }
  if (j > sqrt(n)) {
    return 1;
  } else {
    return 0;
  }
}
long long modexpo(long long a, long long b) {
  long long ans = 1;
  a = a % mod;
  while (b > 0) {
    if ((b & 1) == 1) {
      ans = ((ans % mod) * (a % mod)) % mod;
    }
    b = b >> 1;
    a = ((a % mod) * (a % mod)) % mod;
  }
  return ans;
}
long long invmod(long long n) { return modexpo(n, mod - 2); }
long long comb(long long n, long long r) {
  if (r == 0) {
    return 1;
  }
  long long fact[n + 1];
  fact[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  return (fact[n] * invmod(fact[r]) % mod * invmod(fact[n - r]) % mod) % mod;
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
set<long long> adj[100005];
vector<long long> ans;
bool vis[100005];
void dfs(long long i) {
  ans.push_back(i);
  vis[i] = 1;
  for (auto j : adj[i]) {
    if (vis[j] == 0) {
      bool ok = 0, ok1 = 0;
      for (auto h : adj[j]) {
        if (i == h) {
          ok = 1;
        }
        if (h == ans[(int)ans.size() - 2]) {
          ok1 = 1;
        }
      }
      if (ok == 1 && ok1 == 1) {
        dfs(j);
      }
    }
  }
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
void solve(long long k) {
  long long n, d;
  cin >> n >> d;
  long long a[n];
  vector<vector<long long>> v(200005);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    long long h = a[i], c = 0;
    while (h > 0) {
      v[h].push_back(c);
      h /= 2;
      c++;
    }
  }
  sort(a, a + n);
  long long ans = 10000000;
  for (long long i = 0; i < 200005; i++) {
    sort(v[i].begin(), v[i].end());
    if (int(v[i].size()) < d) continue;
    ans = min(ans, accumulate(v[i].begin(), v[i].begin() + d, 0ll));
  }
  long long r = 0;
  for (long long i = 0; i < d; i++) {
    long long f = a[i];
    while (f > 0) {
      r++;
      f /= 2;
    }
  }
  cout << min(ans, r) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  long long k = 1;
  while (k <= t) {
    solve(k);
    k++;
  }
  return 0;
}
