#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, p;
  cin >> n >> p;
  bool ok = false;
  n -= p;
  for (int i = 1; i < 40 && n >= 0; i++, n -= p) {
    int cnt = __builtin_popcount(n);
    if (cnt <= i && i <= n) {
      cout << i << endl;
      ok = true;
      break;
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  return 0;
}
