#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
long long n, p;
int main() {
  ;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> p;
  for (int i = 1; i < 34 + 1; i += 1) {
    long long cnt = 0;
    long long tn = n - p * i;
    long long mn = 0;
    for (int j = 0; j < 50; j += 1) {
      if ((1LL << j) & tn) {
        mn++;
        cnt += 1LL << j;
      }
    }
    if (cnt >= i && mn <= i) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
