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 long long MAXN = 2e5 + 51, MOD = 998244353, inf = 0x3f3f3f3f;
struct BIT {
  long long sz;
  long long num[MAXN];
  inline void add(long long pos, long long val) {
    for (; pos <= sz; pos += pos & -pos) {
      num[pos] += val;
    }
  }
  inline long long query(long long pos) {
    long long res = 0;
    for (; pos; pos -= pos & -pos) {
      res += num[pos];
    }
    return res;
  }
};
BIT bit;
long long n, kk, flg, tot, sum, wyx, wyxkk, sm1, sm2, res;
long long x[MAXN], t[MAXN], num[MAXN], p[MAXN], c[MAXN];
inline long long read() {
  register long long num = 0, neg = 1;
  register char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') neg = -1, ch = getchar();
  while (isdigit(ch))
    num = (num << 3) + (num << 1) + (ch - '0'), ch = getchar();
  return neg == 1 ? num : -num;
}
inline long long int readu() {
  register long long int num = 0;
  register char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch))
    num = (num << 3) + (num << 1) + (ch - '0'), ch = getchar();
  return num;
}
template <class T>
inline void writep(T x) {
  if (x < 0) {
    return (void)putchar('-'), writep(-x);
  }
  if (x < 10) {
    return (void)putchar(x | 48);
  }
  writep(x / 10), putchar((x % 10) | 48);
}
template <class T>
inline void write(T x, char ch = ' ') {
  writep(x), putchar(ch);
}
template <class T>
inline void writeln(T x) {
  writep(x), putchar('\n');
}
template <class T>
inline void chkmax(T &x, const T &y) {
  x = x > y ? x : y;
}
template <class T>
inline void chkmin(T &x, const T &y) {
  x = x < y ? x : y;
}
template <class T, class Compare>
inline void sort(vector<T> &v, Compare cmp = less<T>()) {
  sort(v.begin(), v.end(), cmp);
}
template <class T>
inline void reverse(vector<T> &v) {
  reverse(v.begin(), v.end());
}
template <class T>
inline void clear(T *arr) {
  memset(arr, 0, sizeof(arr));
}
template <class T>
inline void setInf(T *arr) {
  memset(arr, 0x3f, sizeof(arr));
}
inline long long qpow(long long base, long long exponent) {
  long long int res = 1;
  while (exponent) {
    if (exponent & 1) {
      res = (long long int)res * base % MOD;
    }
    base = (long long int)base * base % MOD, exponent >>= 1;
  }
  return res;
}
inline long long gcd(long long x, long long y) {
  return !y ? x : gcd(y, x % y);
}
inline long long int lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int main() {
  n = bit.sz = read(), kk = read();
  for (register int i = 1; i <= n; i++) {
    sum += (x[i] = read());
  }
  sort(x + 1, x + n + 1);
  for (register int i = 1; i <= n; i++) {
    x[i] != x[i - 1] ? (p[i] = ++tot, num[tot] = i) : p[i] = tot;
    bit.add(p[i], x[i]), t[tot]++;
  }
  num[++tot] = n + 1, res = 1e18;
  for (register int i = 1; i <= n; i++) {
    if (p[i] != p[i - 1]) {
      wyx = num[p[i]] - 1, wyxkk = n - num[p[i] + 1] + 1;
      sm1 = (x[i] - 1) * wyx - bit.query(p[i] - 1);
      sm2 = sum - bit.query(p[i]) - (x[i] + 1) * wyxkk;
      if (t[p[i]] >= kk) {
        return puts("0"), 0;
      }
      flg = 1;
      if (wyx + t[p[i]] >= kk) {
        res = min(res, sm1 + kk - t[p[i]]), flg = 0;
      }
      if (wyxkk + t[p[i]] >= kk) {
        res = min(res, sm2 + kk - t[p[i]]), flg = 0;
      }
      if (flg) {
        res = min(res, sm1 + sm2 + kk - t[p[i]]);
      }
    }
  }
  printf("%lld\n", res);
}
