#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = 0; i < 32; i++) {
    int temp = n - i * p;
    if (__builtin_popcount(temp) <= i && i <= temp) return cout << i, 0;
  }
  cout << -1;
}
