#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > a(n);
  map<long long, long long> freq;
  long long ans = INT_MAX;
  long long win = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = 0;
    freq[a[i].first]++;
    if (win == 0 && freq[a[i].first] >= k) {
      cout << 0;
      win = 1;
    }
  }
  if (win) return 0;
  long long chk = 1;
  while (chk) {
    long long id = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i].first > a[id].first)
        id = i;
      else if (a[i].first == a[id].first && a[i].second < a[id].second)
        id = i;
    }
    freq[a[id].first]--;
    a[id].first /= 2;
    freq[a[id].first]++;
    a[id].second++;
    long long u = a[id].first;
    sort(a.begin(), a.end());
    if (freq[u] >= k) {
      long long l = k;
      long long cnt = 0;
      for (long long i = 0; i < n; i++) {
        if (a[i].first == u) {
          cnt += a[i].second;
          l--;
        }
        if (l == 0) break;
      }
      ans = min(ans, cnt);
    }
    chk = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i].first != 0) {
        chk = 1;
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
