#include <bits/stdc++.h>
int N, p;
int main() {
  scanf("%d%d", &N, &p);
  for (int i = 0; i <= N - p * i; i++)
    if (i >= __builtin_popcount(N - p * i)) {
      printf("%d\n", i);
      return 0;
    }
  puts("-1");
}
