#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << endl;
  err(++it, args...);
}
const long long mod = 1e9 + 7;
const long long maxN = 1e9;
const long long INF = 1e18;
const long double EPS = 1e-9;
long long n, p;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> p;
  long long base2;
  if (n - p < 1)
    cout << -1;
  else {
    int k = 0;
    while (true) {
      k++;
      base2 = n - k * p;
      if (base2 < 1) {
        k = -1;
        break;
      }
      if (__builtin_popcount(base2) <= k) {
        int cnt = 0;
        int temp = 1;
        for (long long i = 0; i <= 31; i++) {
          if (base2 & (1 << i)) cnt += temp;
          temp *= 2;
        }
        if (cnt >= k) break;
      }
    }
    cout << k;
  }
  return 0;
}
