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 = 2e5 + 5;
int n, k;
int arr[N];
long long pre[N];
long long get(int a, int b) {
  if (a > b) return 0;
  return pre[b] - (a > 0 ? pre[a - 1] : 0);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
  }
  sort(arr, arr + n);
  for (int i = 0; i < n; i++) pre[i] = arr[i] + (i > 0 ? pre[i - 1] : 0);
  long long best = 1e18;
  for (int i = 0; i < n; i++) {
    int j = i;
    while (j < n && arr[i] == arr[j]) ++j;
    j--;
    int len = j - i + 1;
    if (len >= k)
      best = 0;
    else {
      int rem = k - len;
      int left = i;
      int right = n - j - 1;
      long long shift_left = 1LL * left * (arr[i] - 1) - get(0, i - 1);
      long long shift_right = get(j + 1, n - 1) - 1LL * right * (arr[i] + 1);
      if (rem > left) {
        long long cost = shift_left + shift_right + rem;
        best = min(best, cost);
      } else {
        long long cost = shift_left + rem;
        best = min(best, cost);
      }
      if (rem > right) {
        long long cost = shift_right + shift_left + rem;
        best = min(best, cost);
      } else {
        long long cost = shift_right + rem;
        best = min(best, cost);
      }
    }
    i = j;
  }
  cout << best << '\n';
  return 0;
}
