#include <bits/stdc++.h>
using namespace std;
int count_ones(int n) {
  int count = 0;
  for (int i = 0; i < 31; i++) {
    if ((n >> i) & 1 == 1) count++;
  }
  return count;
}
int main() {
  int p, n;
  cin >> n >> p;
  n -= p;
  for (int i = 1; n > 0; i++) {
    int c = count_ones(n);
    if (c <= i && n >= i) {
      cout << i;
      break;
    }
    n -= p;
  }
  if (n <= 0) cout << "-1";
  return 0;
}
