#include <bits/stdc++.h>
using namespace std;
int num[2000005];
int cnt[2000005];
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = 0; i <= 10000; i++) {
    int ans = n - i * p;
    int sum = ans;
    if (ans <= 0) break;
    int cnt = 0;
    while (ans) {
      if (ans & 1) cnt++;
      ans >>= 1;
    }
    if (cnt <= i && i <= sum) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
