#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1 << 30;
const long long inf_longlong = 1LL << 62;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int n, p;
int pow(int a, int b) { return b ? pow(a * a, b / 2) * (b & 1 ? a : 1) : 1; }
void read_input() { cin >> n >> p; }
void solve() {
  for (int i = 1; i < 1000; i++) {
    long long k = 1LL * n - i * p;
    if (k < 0) continue;
    int cur = 0;
    vector<int> V;
    while (k) {
      if (k & 1) V.push_back(cur);
      k >>= 1;
      cur++;
    }
    int need = i - (int)V.size();
    if (need < 0) continue;
    int sum = 0;
    for (auto it : V) sum += pow(2, it) - 1;
    if (sum >= need) {
      cout << i << '\n';
      return;
    }
  }
  cout << -1 << '\n';
}
void write_output() {}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int test_cases = 1;
  while (test_cases--) {
    read_input(), solve(), write_output();
  }
  return 0;
}
