#include <bits/stdc++.h>
using namespace std;
int n, k, ans = -1;
int main() {
  cin >> n >> k;
  int i;
  for (i = 0; i <= 30 && n >= 0; i++, n -= k) {
    if (__builtin_popcount(n) <= i && n >= i) {
      ans = i;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
