#include <bits/stdc++.h>
using namespace std;
long long n, p;
inline long long read() {
  long long sum = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();
  return sum * ff;
}
signed main() {
  n = read();
  p = read();
  for (long long i = 1; i <= 60; i++) {
    n -= p;
    if (__builtin_popcount(n) <= i && i <= n) return printf("%lld", i), 0;
  }
  return puts("-1"), 0;
}
