#include <bits/stdc++.h>
long long lowbit(long long x) { return x & (-x); };
using namespace std;
int main() {
  long long ans = -1;
  long long x, p;
  scanf("%lld %lld", &x, &p);
  for (long long i = x - 33000; i <= x + 33000; i++) {
    if (i <= 0) continue;
    long long num = 0;
    long long g = i;
    while (g) {
      g -= lowbit(g);
      num++;
    }
    if (p != 0) {
      if ((x - i) % p == 0) {
        long long g0 = (x - i) / p;
        if (num <= g0 && g0 <= i) {
          if (ans == -1 || ans > g0) {
            ans = g0;
          }
        }
      }
    } else {
      if (i == x) ans = num;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
