#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, p;
int bin[32] = {0};
bool check(int x) {
  int m = n - x * p;
  int res = 0;
  if (m < x) return 0;
  for (int i = 0; i <= 31; i++)
    if (m & bin[i]) {
      x--;
      if (x < 0) return 0;
    }
  return 1;
}
int main() {
  bin[0] = 1;
  for (int i = 1; i <= 31; i++) bin[i] = bin[i - 1] << 1;
  n = read();
  p = read();
  for (int i = 1; i <= 100; i++)
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  puts("-1");
  return 0;
}
