#include <bits/stdc++.h>
using namespace std;
int n, p, x;
int main() {
  scanf("%d%d", &n, &p);
  for (int i = 1; i <= 1000; ++i) {
    int tmp = n - i * p;
    if (tmp < 0) continue;
    if (tmp < i) continue;
    int cnt = 0;
    while (tmp) tmp -= (tmp & (-tmp)), ++cnt;
    if (cnt <= i) return printf("%d", i), 0;
  }
  return puts("-1"), 0;
}
