#include <bits/stdc++.h>
int inp() {
  char c = getchar();
  int neg = 1;
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum * neg;
}
int n, p;
int main() {
  n = inp();
  p = inp();
  for (int i = 1; i <= 1000; i++) {
    if (n - (i * p) <= 0) break;
    if (__builtin_popcount(n - (i * p)) <= i && i <= (n - (i * p))) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
}
