#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
vector<long long int> check(long long int n) {
  long long int cnt = 0;
  vector<long long int> v;
  while (n > 0) {
    if (n & 1) {
      v.push_back(cnt);
    }
    n = n >> 1;
    cnt++;
  }
  return v;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    long long int n, p;
    cin >> n >> p;
    if (n - p <= 0) {
      cout << "-1" << endl;
      continue;
    }
    if (p == 0) {
      vector<long long int> v = check(n);
      cout << v.size() << endl;
      continue;
    }
    long long int x = 1;
    long long int ans = -1;
    while (n - x * p > 0) {
      long long int tmp = n - x * p;
      vector<long long int> v = check(tmp);
      long long int siz = v.size();
      if (siz == x) {
        ans = x;
        break;
      } else {
        long long int sum = 0;
        for (int i = 0; i < v.size(); i++) sum += v[i];
        if (sum >= x && siz < x) {
          ans = x;
          break;
        }
      }
      x++;
    }
    cout << ans << endl;
  }
  return 0;
}
