#include <bits/stdc++.h>
using namespace std;
const long long P = 998244353;
const int INF = 0x3fffffff;
const int N = 1005;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, p, ans = -1;
int main() {
  cin >> n >> p;
  for (int i = (1); i <= (100); ++i) {
    int x = n - p * i;
    if (x >= i && __builtin_popcount(x) <= i) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
