#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, p, i;
  cin >> n >> p;
  vector<long long int> power(31, 0);
  for (i = 0; i < 31; i++) {
    power[i] = pow(2, i);
  }
  long long int ans = INT_MAX;
  for (i = 1; i < 31; i++) {
    long long int num = n - i * p;
    if (i > num) break;
    if (num == 1) {
      long long int c = 0;
      while (num != 0) {
        num &= (num - 1);
        c++;
      }
      if (c != i) {
        continue;
      } else
        ans = i;
    }
    if (num < 1) {
      break;
    }
    long long int c = 0;
    while (num != 0) {
      num &= (num - 1);
      c++;
    }
    if (c == i) {
      ans = i;
      break;
    } else if (c < i) {
      ans = i;
      break;
    }
  }
  if (ans != INT_MAX)
    cout << ans << endl;
  else
    cout << "-1" << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) solve();
  return 0;
}
