#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M, i, t, x, con, ok = 1;
  scanf("%lld %lld", &N, &M);
  for (i = 0; 100; i++) {
    x = N - i * M;
    if (x < 0) break;
    con = 0;
    while (x > 0) {
      if (x % 2) con++;
      x /= 2;
    }
    if (con <= i && (N - i * M) >= i) {
      printf("%d\n", i);
      ok = 0;
      break;
    }
  }
  if (ok) printf("-1\n");
  return 0;
}
