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;
const int N = 1e6 + 6;
const int mod = 1e9 + 7;
template <typename T>
int O(const T &s) {
  cout << s << endl;
  return 0;
}
template <typename T>
void db(T *bg, T *ed) {
  while (bg != ed) cout << *bg++ << ' ';
  printf("\n");
}
template <typename T>
void db(vector<T> &it) {
  for (auto i : it) cout << i << ' ';
  printf("\n");
}
inline long long mul_64(long long x, long long y, long long c) {
  return (x * y - (long long)((long double)x / c * y) * c + c) % c;
}
inline long long ksm(long long a, long long b, long long c) {
  long long ans = 1;
  for (; b; b >>= 1, a = a * a % c)
    if (b & 1) ans = ans * a % c;
  return ans;
}
inline void exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b)
    x = 1, y = 0;
  else
    exgcd(b, a % b, y, x), y -= (a / b) * x;
}
int n, k;
int a[N], x = 0, cnt = 0;
long long pre[N], suf[N];
int main() {
  cin >> n >> k;
  for (int i = 0; i++ < n; scanf("%d", &a[i]))
    ;
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
  for (int i = n; i >= 1; i--) suf[i] = suf[i + 1] + a[i];
  for (int i = 2; i <= n; i++)
    if (a[i] == a[i - 1])
      x++;
    else
      cnt = max(cnt, x), x = 1;
  cnt = max(cnt, x);
  if (cnt >= k) return O(0);
  long long ans = 1e18 + 11;
  for (int i = 1; i <= n; i++) {
    long long res = 1LL * (i - 1) * a[i] - pre[i - 1] - 1LL * a[i] * (n - i) +
                    suf[i + 1] - (n - k);
    if (i >= k) res = min(res, 1LL * (i - 1) * a[i] - pre[i - 1] - (i - k));
    if (n - i + 1 >= k)
      res = min(res, suf[i + 1] - 1LL * (n - i) * a[i] - (n - i + 1 - k));
    ans = min(ans, res);
  }
  O(ans);
}
