#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n, p;
  cin >> n >> p;
  for (int i = 1; i < 100; i++) {
    n -= p;
    if (n <= 0) {
      cout << -1;
      return 0;
    }
    long long q = 0, t = n;
    while (t > 0) {
      q += (t & 1);
      t >>= 1;
    }
    if (q <= i && n >= i) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1;
  return 0;
}
