#include <bits/stdc++.h>
using namespace std;
long long number[40];
vector<int> binary(long long a) {
  vector<int> ans;
  if (a == 0) ans.push_back(0);
  while (a) {
    ans.push_back(a % 2);
    a /= 2;
  }
  vector<int> ans1;
  for (int i = ans.size() - 1; i >= 0; i--) ans1.push_back(ans[i]);
  return ans1;
}
long long binpow(long long a, long long n) {
  if (n == 0) return 1;
  if (n & 1) {
    return binpow(a, n - 1) * a;
  } else {
    long long t = binpow(a, n / 2);
    return t * t;
  }
}
int main() {
  long long n, p;
  cin >> n >> p;
  long long min = 5e9;
  for (int i = 1; i <= 30; i++) {
    long long copy = n - p * i;
    if (copy < 0) continue;
    vector<int> count = binary(copy);
    long long c = 0;
    for (int j = 0; j < count.size(); j++)
      if (count[j]) c++;
    if (c > i) continue;
    if (c == i) {
      cout << c;
      return 0;
    }
    c = 0;
    for (int j = 0; j < count.size(); j++) {
      if (count[j]) {
        c += binpow((long long)2, (long long)count.size() - 1 - j);
      }
    }
    if (c >= i) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
