#include <bits/stdc++.h>
using namespace std;
inline long long gi() {
  long long f = 1, sum = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
long long n, p;
long long lowbit(long long x) { return x & (-x); }
bool check(long long x, long long mx) {
  long long ret = 0, tmp = x;
  while (x) {
    ret++;
    x ^= lowbit(x);
  }
  return ret <= mx && mx <= tmp;
}
signed main() {
  n = gi();
  p = gi();
  for (long long i = 1; n - i * p > 0 && i <= 2000000; i++)
    if (check(n - i * p, i)) return printf("%lld\n", i), 0;
  puts("-1");
  return 0;
}
