#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long mod1 = 1000000009;
const long long base = 10529;
const long long base1 = 11699;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, p;
  cin >> n >> p;
  for (long long i = 0; i <= 50; i++) {
    if (n >= i * p) {
      long long pp = __builtin_popcount(n - p * i);
      if (i <= n - p * i and i >= pp) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
