#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p;
  while (cin >> n >> p) {
    long long ans = 0;
    long long tmp = n, cnt = 0, tmp1;
    bool l = 0;
    while (tmp > 0) {
      tmp1 = 0;
      for (int i = 0; i < 32; ++i) {
        if ((1ll << i) & tmp) {
          ++tmp1;
        }
      }
      if (cnt >= tmp1 && cnt <= tmp) {
        ans = cnt;
        l = 1;
        break;
      }
      tmp -= p;
      ++cnt;
    }
    if (l)
      cout << cnt << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
