#include <bits/stdc++.h>
using namespace std;
int n, k, f[22][200005], m, x, sum, cur, ans;
void calc(int x) {
  int cur = 0;
  while (x) {
    f[cur][x]++;
    x >>= 1;
    cur++;
  }
  f[cur][0]++;
}
int main() {
  cin >> n >> k;
  ans = 1e9;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    calc(x);
    m = max(m, x);
  }
  for (int i = 0; i <= m; i++) {
    cur = 0;
    sum = 0;
    for (int j = 0; j <= 20; j++) {
      if (sum + f[j][i] >= k) {
        cur += (k - sum) * j;
        ans = min(ans, cur);
        break;
      } else {
        sum += f[j][i];
        cur += f[j][i] * j;
      }
    }
  }
  cout << ans;
  return 0;
}
