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>
const long long N = 2e5 + 5;
long long a[N], num[N], cnt[N];
long long pre[N], suf[N], pcnt[N], scnt[N];
long long ans = 1e18;
using namespace std;
long long quick_power_mod(long long a, long long b, long long m) {
  a %= m;
  long long result = 1;
  while (b > 0) {
    if (b & 1) result = (result * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return result;
}
long long comp(long long a, long long b, long long p) {
  if (a < b) return 0;
  if (a == b) return 1;
  if (b > a - b) b = a - b;
  long long ans = 1, ca = 1, cb = 1;
  for (long long i = 0; i < b; i++) {
    ca = (ca * (a - i)) % p;
    cb = (cb * (b - i)) % p;
  }
  ans = (ca * quick_power_mod(cb, p - 2, p)) % p;
  return ans;
}
long long lucas(long long n, long long m, long long p) {
  long long ans = 1;
  while (n && m && ans) {
    ans = (ans * comp(n % p, m % p, p)) % p;
    n /= p;
    m /= p;
  }
  return ans;
}
long long ssum(long long x) {
  long long s = 0;
  for (long long i = 0; i < x; i++) {
    s += i;
  }
  return s;
}
long long visss[1005];
void PPrime() {
  for (long long i = 2; i < 1000; i++) {
    if (visss[i] == 0) {
      for (long long j = 2 * i; j < 1000; j += i) {
        visss[j] = 1;
      }
    }
  }
}
long long n, k;
long long C(long long x) { return x * (x - 1) / 2; }
bool solve(long long i) {
  long long num = C(n - i);
  long long temp = k - num;
  if (temp <= n - i) {
    long long x = i, y = n - temp + 1;
    for (long long i = 1; i <= n; i++)
      if (i != x && i != y)
        printf("a");
      else
        printf("b");
    puts("");
    return 1;
  }
  return 0;
}
vector<long long> f, g;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  lucas(1000, 100, 1000007);
  lucas(1000, 200, 1000007);
  ssum(100);
  PPrime();
  long long n, k, m = 0;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  long long S = 0;
  for (long long i = 1; i <= n; i++) {
    S++;
    if (a[i] != a[i + 1]) {
      m++;
      num[m] = a[i], cnt[m] = S;
      S = 0;
    }
  }
  for (long long i = 2; i <= m; i++) {
    pre[i] = pre[i - 1] + pcnt[i - 1] * (num[i] - num[i - 1]) +
             cnt[i - 1] * (num[i] - num[i - 1] - 1);
    pcnt[i] = pcnt[i - 1] + cnt[i - 1];
  }
  for (long long i = m - 1; i >= 1; i--) {
    suf[i] = suf[i + 1] + scnt[i + 1] * (num[i + 1] - num[i]) +
             cnt[i + 1] * (num[i + 1] - num[i] - 1);
    scnt[i] = scnt[i + 1] + cnt[i + 1];
  }
  for (long long i = 1; i <= m; i++) {
    long long res = k - cnt[i];
    if (res <= 0) {
      cout << "0";
      return 0;
    }
    if (i > 1 && i < m) ans = min(ans, pre[i] + suf[i] + res);
    if (i > 1 && pcnt[i] >= res) ans = min(ans, pre[i] + res);
    if (i < m && scnt[i] >= res) ans = min(ans, suf[i] + res);
  }
  cout << ans << '\n';
  return 0;
}
