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>
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
template <class T>
auto dud(T *x) -> decltype(cout << *x, 0);
template <class T>
char dud(...);
struct debug {
  template <class T>
  debug &operator<<(const T &) {
    return *this;
  }
};
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
const ld eps = (ld)1e-9;
const ll MOD = (ll)1e9 + 7;
const ld PI = acos(-1);
const int N = (int)5e5 + 5;
template <class T>
T gcd(T x, T y) {
  return (y == 0) ? x : gcd(y, x % y);
}
template <class T>
void mini(T &a, T b) {
  a = min(a, b);
}
template <class T>
void maxi(T &a, T b) {
  a = max(a, b);
}
template <class T>
T mul(T x, T y) {
  return (x * y) % MOD;
}
template <class T>
inline T power(T a, T b) {
  T res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res % MOD;
}
template <class T>
inline T modInverse(T n) {
  return power(n, MOD - 2, MOD) % MOD;
}
template <class T>
inline void add(T &x, T y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
template <class T>
inline void sub(T &x, T y) {
  x -= y;
  if (x < 0) x += MOD;
}
template <class T>
inline T power(T a, T b, T mod) {
  T res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res % mod;
}
template <class T>
inline T modInverse(T n, T p) {
  return power(n, p - 2, p) % p;
}
template <class T, class U>
string to_string(pair<T, U> p) {
  return to_string(p.first) + " " + to_string(p.second);
}
bool is_digit(char x) { return x >= '0' && x <= '9'; }
bool is_upper(char x) { return x >= 'A' && x <= 'Z'; }
bool is_lower(char x) { return x >= 'a' && x <= 'z'; }
bool is_char(char x) {
  return x == '!' || x == '@' || x == '#' || x == '$' || x == '%' || x == '&';
}
template <class T>
inline bool isPrime(T n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (ll i = 5; i * i <= n; i += 6) {
    if ((n % i == 0) || (n % (i + 2) == 0)) {
      return false;
    }
  }
  return true;
}
inline void to_upper(string &s) {
  transform((s).begin(), (s).end(), s.begin(), ::toupper);
}
inline void to_lower(string &s) {
  transform((s).begin(), (s).end(), s.begin(), ::tolower);
}
class D2EqualizingByDivisionHardVersion {
 public:
  void solve(std::istream &cin, std::ostream &cout) {
    int n, k, x;
    cin >> n >> k;
    map<int, vi> g;
    for (int i = 0; i < n; ++i) {
      cin >> x;
      for (int j = 0; x; j++, x /= 2) {
        g[x].push_back(j);
      }
    }
    int ans = INT_MAX;
    for (auto &[xx, mp] : g) {
      if ((int)(mp).size() >= k) {
        sort((mp).begin(), (mp).end());
        int sum = 0;
        for (int j = 0; j < k; ++j) {
          sum += mp[j];
        }
        mini(ans, sum);
      }
    }
    cout << ans << endl;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(12);
  D2EqualizingByDivisionHardVersion solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}