#include <bits/stdc++.h>
using namespace std;
int n, p;
int aux(int x) {
  int res = 0;
  while (x > 0) res++, x = x & (x - 1);
  return res;
}
int main() {
  scanf("%d%d", &n, &p);
  int ans = -1, cnt = 0;
  while (1) {
    n -= p, cnt++;
    if (n < 0) break;
    if (aux(n) <= cnt && n >= cnt) {
      ans = cnt;
      break;
    }
  }
  cout << ans << endl;
}
