#include <bits/stdc++.h>
using namespace std;
template <class R>
inline void Readin(R &K) {
  bool F = K = 0;
  char C = getchar();
  while (C < '0' || C > '9') {
    if (C == '-') F = 1;
    C = getchar();
  }
  while (C <= '9' && C >= '0') K = (K << 1) + (K << 3) + C - '0', C = getchar();
  if (F) K = -K;
}
template <class R>
inline bool Checkmax(R &A, R B) {
  return A < B ? A = B, 1 : 0;
}
template <class R>
inline bool Checkmin(R &A, R B) {
  return A > B ? A = B, 1 : 0;
}
inline int Bit(int A) {
  if (A <= 0) return 100000;
  int Ans = 0;
  while (A) {
    Ans += A & 1;
    A >>= 1;
  }
  return Ans;
}
int main() {
  int A, B;
  Readin(A);
  Readin(B);
  for (register int i = 1; i <= 32; ++i)
    if (Bit(A - i * B) <= i and A - i * B >= i) return not printf("%d\n", i);
  return not printf("-1\n");
}
