Problem: 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
const long long N = 100005;
using namespace std;
void pairsort(long long a[], long long b[], long long n) {
  pair<long long, long long> pairt[n];
  for (long long i = 0; i < n; i++) {
    pairt[i].first = a[i];
    pairt[i].second = b[i];
  }
  sort(pairt, pairt + n);
  for (long long i = 0; i < n; i++) {
    a[i] = pairt[i].first;
    b[i] = pairt[i].second;
  }
}
bool isPrime(long long n) {
  if (n < 2) return 0;
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
long long factorial(long long n) {
  long long i = 1;
  for (long long j = 1; j <= n; j++) i *= j;
  return i;
}
long long nCr(long long n, long long r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}
long double modd(long double x) {
  if (x >= 0) return x;
  return -1 * x;
}
long long dp(long long y) {
  long long s = 0;
  while (y != 0) {
    long long r = y % 10;
    s += r;
    y /= 10;
  }
  if (s % 10 == 0) return 1;
  return 0;
}
long long sd(long long n) {
  long long s = 0;
  while (n != 0) {
    s += n % 10;
    n /= 10;
  }
  return s;
}
long long mod = 998244353;
long long modexpo(long long x, unsigned long long y) {
  long long res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long ps(long long n) {
  long double x = (long double)n;
  if (ceil(sqrt(x)) == floor(sqrt(x))) return 1;
  return 0;
}
vector<long long> adj[N];
vector<long long> cost;
long long src, des, w, u, v;
vector<long long> vis;
vector<long long> dist, res, parent;
long long n, k;
long long p = 1;
void dfs(long long x) {
  vis[x] = 1;
  for (long long i = 0; i < adj[x].size(); i++) {
    if (!vis[adj[x][i]]) {
      dfs(adj[x][i]);
    }
  }
}
void bfs() {
  long long s = 1;
  queue<long long> q;
  q.push(s);
  parent[s] = 1;
  vis[s] = 1;
  while (!q.empty()) {
    s = q.front();
    q.pop();
    for (long long i = 0; i < adj[s].size(); i++) {
      if (!vis[adj[s][i]]) {
        q.push(adj[s][i]);
        vis[adj[s][i]] = 1;
        parent[adj[s][i]] = s;
      }
    }
  }
}
long long g, h;
bool prime[1000005];
vector<long long> pp;
void sieve() {
  memset(prime, true, sizeof(prime));
  long long n = 1000005;
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
long long mod1(string num, long long a) {
  long long res = 0;
  for (long long i = 0; i < num.length(); i++)
    res = (res * 10 + (long long)num[i] - '0') % a;
  return res;
}
long long reach(long long x, long long y) {
  while (x != 0) {
    if (x == y) return 1;
    x /= 2;
  }
  if (x == y) return 1;
  return 0;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ma = *max_element(a, a + n);
  vector<map<long long, long long> > vv;
  for (long long i = 0; i < n; i++) {
    map<long long, long long> ans;
    long long x = a[i];
    long long ct = 0;
    ans[x] = 0;
    while (x != 0) {
      ct++;
      x /= 2;
      ans[x] = ct;
    }
    ans[x] = ct;
    vv.push_back(ans);
  }
  long long mi = 1e9, temp = 0;
  for (long long i = 0; i <= ma; i++) {
    temp = 0;
    vector<long long> xx;
    for (long long j = 0; j < n; j++) {
      if (reach(a[j], i) == 1) xx.push_back(vv[j][i]);
    }
    sort(xx.begin(), xx.end());
    if (xx.size() >= k) {
      for (long long j = 0; j < k; j++) temp += xx[j];
      mi = (mi < temp ? mi : temp);
    }
  }
  cout << mi;
}