#include <bits/stdc++.h>
using namespace std;
int n, p;
int check(int x) {
  int ans = 0;
  while (x) {
    ans += x % 2;
    x /= 2;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> p;
  for (int i = 1; i <= 31; ++i) {
    if (n - i * p <= 0) break;
    int cur = check(n - i * p);
    if (cur <= i && i <= n - i * p) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}
