#include <bits/stdc++.h>
using namespace std;
int n, p, ans;
int main() {
  ans = 1 << 30;
  scanf("%d%d", &n, &p);
  for (int i = (int)(0); i <= (int)(30); i++) {
    int nn = n - i * p;
    if (nn < 0) continue;
    int sum = 0;
    for (int j = (int)(0); j <= (int)(30); j++) sum += (nn >> j) & 1;
    if (nn >= i && sum <= i) return printf("%d\n", i), 0;
  }
  puts("-1");
}
