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 Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
inline int sbt(int x) { return __builtin_popcount(x); }
inline long long gl(long long a, long long b) { return (b - a + 1); }
inline long long mul(long long a, long long b,
                     long long m = (long long)(1e9 + 7)) {
  return ((a % m) * (b % m)) % m;
}
inline long long add(long long a, long long b,
                     long long m = (long long)(1e9 + 7)) {
  return (a + b) % m;
}
inline long long sub(long long a, long long b,
                     long long m = (long long)(1e9 + 7)) {
  return (a - b + m) % m;
}
long long fastpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
long long modinv(long long a) { return fastpow(a, (long long)(1e9 + 7) - 2); }
void get_ac() {
  long long n, k;
  cin >> n >> k;
  long long a[n], p[n], s[n];
  map<long long, long long> m;
  for (long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  sort(a, a + n);
  p[0] = a[0];
  for (auto i = 1; i <= n - 1; i++) {
    p[i] = p[i - 1] + a[i];
  }
  s[n - 1] = a[n - 1];
  for (auto i = n - 2; i >= 0; i--) {
    s[i] = s[i + 1] + a[i];
  }
  long long ans = 1e15;
  long long sm, lg, lgc, smc, eq;
  for (int i = 0; i < n; i++) {
    sm = lower_bound(a, a + n, a[i]) - a;
    eq = m[a[i]];
    if (eq >= k) {
      cout << 0;
      return;
    }
    lg = n - sm - eq;
    smc = (a[i] - 1) * sm - (sm ? p[sm - 1] : 0);
    if (sm + eq >= k) ans = min(ans, max(0LL, smc + k - eq));
    lgc = (lg != 0 ? s[n - lg] : 0) - (a[i] + 1) * lg;
    if (lg + eq >= k) ans = min(ans, max(0LL, lgc + k - eq));
    ans = min(ans, max(0LL, smc + lgc + k - eq));
  }
  cout << ans;
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin.tie(NULL);
  { get_ac(); }
  return 0;
}
