#include <bits/stdc++.h>
using namespace std;
long long n, p;
int get(int x) {
  int sum = 0;
  while (x) {
    if (x & 1) sum++;
    x >>= 1;
  }
  return sum;
}
int main() {
  scanf("%lld%lld", &n, &p);
  int sum = 0;
  while (n - sum * p > 0) {
    int s = get(n - sum * p);
    if (sum >= s && sum <= n - sum * p) {
      printf("%d\n", sum);
      return 0;
    }
    sum++;
  }
  puts("-1");
}
