#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  cin >> n >> t;
  int a[n];
  map<int, bool> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  vector<int> s;
  s.push_back(0);
  for (int i = 0; i < n; i++) {
    int x = a[i];
    while (x > 0) {
      if (m[x] == false) {
        s.push_back(x);
        m[x] = true;
      }
      x = x / 2;
    }
  }
  int l = INT_MAX;
  for (int i = 0; i < s.size(); i++) {
    int c = 0, k = 0;
    for (int j = 0; j < n; j++) {
      int u = a[j];
      int y = 0;
      while (u > s[i]) {
        u = u / 2;
        y++;
      }
      if (u == s[i]) {
        k++;
        c = c + y;
      }
      if (k == t) {
        l = min(l, c);
        break;
      }
    }
  }
  cout << l;
  return 0;
}
