#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  int ans = 50;
  for (int(i) = (1); (i) <= (30); (i)++) {
    int tar = n - i * p;
    if (tar >= i && __builtin_popcount(tar) <= i) ans = min(ans, i);
  }
  printf("%d", ans > 35 ? -1 : ans);
}
