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;
template <typename A, typename B>
string my_to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string my_to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string my_to_string(tuple<A, B, C, D> p);
string my_to_string(const string& s) { return '"' + s + '"'; }
string my_to_string(const char* s) { return my_to_string((string)s); }
string my_to_string(bool b) { return (b ? "true" : "false"); }
string my_to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += my_to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string my_to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
string my_to_string(uint8_t a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(uint16_t a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(uint32_t a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(uint64_t a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(int8_t a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(int16_t a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(int32_t a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(int64_t a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(float a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(double a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(long double a) {
  ostringstream ss;
  ss << a;
  return ss.str();
}
string my_to_string(char a) {
  ostringstream ss;
  ss << '\'' << a << '\'';
  return ss.str();
}
template <typename A>
string my_to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += my_to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string my_to_string(pair<A, B> p) {
  return "(" + my_to_string(p.first) + ", " + my_to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string my_to_string(tuple<A, B, C> p) {
  return "(" + my_to_string(get<0>(p)) + ", " + my_to_string(get<1>(p)) + ", " +
         my_to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string my_to_string(tuple<A, B, C, D> p) {
  return "(" + my_to_string(get<0>(p)) + ", " + my_to_string(get<1>(p)) + ", " +
         my_to_string(get<2>(p)) + ", " + my_to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << my_to_string(H);
  debug_out(T...);
}
const int MX = 2e5 + 99;
int n, k;
long long a[MX];
map<int, int> M;
long long solveX(long long X) {
  long long cntL = 0;
  long long cntR = 0;
  long long sumL = 0, sumR = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < X) {
      sumL += (X - 1 - a[i]);
      cntL++;
    } else if (X < a[i]) {
      sumR += a[i] - (X + 1);
      cntR++;
    }
  }
  long long cntX = M[X];
  long long result = sumL + sumR + (k - cntX);
  if (cntL + cntX >= k) {
    result = min(result, sumL + (k - cntX));
  }
  if (cntR + cntX >= k) {
    result = min(result, sumR + (k - cntX));
  }
  42;
  return result;
}
long long solve() {
  sort(a, a + n);
  for (int i = 0; i < n; i++) M[a[i]]++;
  for (auto it : M) {
    if (it.second >= k) return 0;
  }
  set<long long> S;
  int mn = a[0], mx = a[n - 1];
  for (int i = 0; i < n; i++) {
    S.insert(a[i]);
    if (mn <= a[i] - 1) S.insert(a[i] - 1);
    if (a[i] + 1 <= mx) S.insert(a[i] + 1);
  }
  long long res = 1e15;
  42;
  long long cntL = 0, cntR = 0, sumL = 0, sumR = 0;
  int itL = 0, itR = n - 1;
  for (long long X : S) {
    while (itL < n && a[itL] <= X - 1) {
      cntL++;
      sumL += a[itL];
      itL++;
    }
    while (0 <= itR && X + 1 <= a[itR]) {
      cntR++;
      sumR += a[itR];
      itR--;
    }
    while (itR + 1 < n && a[itR + 1] < X + 1) {
      itR++;
      sumR -= a[itR];
      cntR--;
    }
    long long sumL2 = (X - 1) * cntL - sumL;
    long long sumR2 = sumR - (X + 1) * cntR;
    long long cntX = M[X];
    long long result = sumL2 + sumR2 + (k - cntX);
    if (cntL + cntX >= k) {
      result = min(result, sumL2 + (k - cntX));
    }
    if (cntR + cntX >= k) {
      result = min(result, sumR2 + (k - cntX));
    }
    res = min(res, result);
  }
  42;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << solve();
  return 0;
}
