#include <bits/stdc++.h>
using namespace std;
const int LOG = 31;
int n, p;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> p;
  int ans = -1;
  for (int i = 1; i <= LOG; i++) {
    n -= p;
    if (__builtin_popcount(n) <= i && n >= i) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}
