#include <bits/stdc++.h>
using namespace std;
long long num[10010000];
int main() {
  ios::sync_with_stdio(0);
  long long n, p;
  cin >> n >> p;
  long long w = 1;
  while (1) {
    long long num = (n - (w * p));
    long long a = __builtin_popcount(num);
    if (num <= 0) {
      cout << -1 << endl;
      return 0;
    }
    if (w >= a && (w <= num)) {
      cout << w << endl;
      return 0;
    }
    w++;
  }
  return 0;
}
