#include <bits/stdc++.h>
using namespace std;
bool check(long long int val, int st) {
  int c = 0;
  long long int tem = val;
  while (val != 0) {
    c += val % 2;
    val = val / 2;
  }
  if (c <= st && st <= tem) return true;
  return false;
}
int main() {
  long long int n;
  int p;
  cin >> n >> p;
  if (n <= p)
    cout << -1;
  else {
    int fl = -1;
    for (int i = 1; i < 10001; i++) {
      long long int te = n;
      te = te - p * i;
      if (check(te, i)) {
        fl = i;
        break;
      }
    }
    cout << fl;
  }
}
