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>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
constexpr int INF = INT_MAX / 10;
constexpr long long LINF = LLONG_MAX / 10;
constexpr double eps = 1e-9;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
using namespace std;
inline long long gcd(long long a, long long b) {
  while (b) {
    long long c = a;
    a = b;
    b = c % b;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool isprime(long long n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long mypow(long long a, long long b) {
  if (!b) return 1;
  if (b & 1) return mypow(a, b - 1) * a;
  long long memo = mypow(a, b >> 1);
  return memo * memo;
}
long long modpow(long long a, long long b, long long m) {
  if (!b) return 1;
  if (b & 1) return modpow(a, b - 1, m) * a % m;
  long long memo = modpow(a, b >> 1, m);
  return memo * memo % m;
}
void printArray(vector<int>& vec) {
  for (int i = 0; i < (vec.size() - 1); i++) cout << vec[i] << " ";
  cout << vec.back() << endl;
}
int n, k;
long long a[200010], dp[2][200010];
map<int, int> c;
signed main() {
  cin >> n >> k;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    c[a[i]]++;
  }
  sort(a, a + n);
  dp[0][0] = 0;
  for (int i = 1; i <= (n - 1); i++) {
    if (a[i - 1] == a[i])
      dp[0][i] = dp[0][i - 1];
    else {
      dp[0][i] = dp[0][i - 1] + (long long)i * (a[i] - a[i - 1]);
    }
  }
  dp[1][n - 1] = 0;
  for (int i = n - 2; i >= 0; i--) {
    if (a[i + 1] == a[i])
      dp[1][i] = dp[1][i + 1];
    else {
      dp[1][i] = dp[1][i + 1] + (long long)(n - i - 1) * (a[i + 1] - a[i]);
    }
  }
  if (c.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  long long ans = LINF, memo = 0, left = 0;
  for (int i = 0; i < (n - 1); i++) {
    if (k <= c[a[i]]) {
      cout << 0 << endl;
      return 0;
    }
    if (a[i] == a[i + 1]) continue;
    if (k <= i + 1) {
      chmin(ans, memo + (a[i] - a[left - 1] - 1) * left + k - c[a[i]]);
    }
    if (k <= n - left) {
      chmin(ans,
            dp[1][i + 1] + (a[i + 1] - a[i] - 1) * (n - i - 1) + k - c[a[i]]);
    }
    if (left)
      chmin(ans, memo + dp[1][i + 1] + (a[i] - a[left - 1] - 1) * left +
                     (a[i + 1] - a[i] - 1) * (n - i - 1) + k - c[a[i]]);
    memo = dp[0][i];
    left = i + 1;
  }
  chmin(ans, memo + (a[n - 1] - a[left - 1] - 1) * left + k - c[a[n - 1]]);
  cout << ans << endl;
  return 0;
}
