#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  int mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]);
  }
  int ans = INT_MAX;
  for (int x = 0; x <= mx; x++) {
    vector<int> v;
    for (int i = 0; i < n; i++) {
      int r = a[i];
      int moves = 0;
      while (r > x) {
        r /= 2;
        moves++;
      }
      if (r == x) v.push_back(moves);
    }
    if ((int)v.size() < k) continue;
    sort(v.begin(), v.end());
    int s = 0;
    for (int i = 0; i < k; i++) s += v[i];
    ans = min(ans, s);
  }
  cout << ans << "\n";
}
