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;
template <typename T>
T gcd(T a, T b) {
  return !b ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a * (b / gcd(a, b));
}
template <typename T>
T sqr(T a) {
  return a * a;
}
template <typename T>
T cube(T a) {
  return a * a * a;
}
template <typename T>
inline void smin(T &a, T b) {
  a = a < b ? a : b;
}
template <typename T>
inline void smax(T &a, T b) {
  a = a > b ? a : b;
}
template <typename T>
inline void Int(T &n) {
  n = 0;
  int f = 1;
  register int ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
vector<string> split(const string &s, char c) {
  vector<string> v;
  stringstream second(s);
  string x;
  while (getline(second, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", ";
  err(++it, args...);
}
inline int in() {
  int n;
  scanf("%d", &n);
  return n;
}
inline long long Lin() {
  long long n;
  scanf("%lld", &n);
  return n;
}
inline double Din() {
  double n;
  scanf("%lf", &n);
  return n;
}
inline int add(int a, int b, int mod) {
  a += b;
  return a >= mod ? a - mod : a;
}
inline int sub(int a, int b, int mod) {
  a -= b;
  return a < 0 ? a + mod : a;
}
inline int mul(int a, int b, int mod) { return (long long)a * b % mod; }
const int N = 2e5 + 5;
const int inf = (int)2e9 + 5;
const long long Inf = (long long)1e18 + 5;
const int mod = (int)1e9 + 7;
const long long Mod = (long long)1e9 + 7;
vector<int> b[N];
int solve() {
  int n = in(), k = in();
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    a[i] = in();
  }
  for (int i = 0; i < n; i++) {
    int x = a[i], cur = 0;
    while (x >= 1) {
      b[x].push_back(cur);
      x /= 2;
      cur++;
    }
  }
  long long ans = Inf;
  for (int i = 0; i <= 2e5; i++) {
    sort(b[i].begin(), b[i].end());
    if ((int)b[i].size() >= k) {
      long long cur = 0;
      for (int j = 0; j < k; j++) {
        cur += b[i][j];
      }
      smin(ans, cur);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
int main() {
  int test = 1, tc = 0;
  while (test--) {
    solve();
  }
  return 0;
}
