#include <bits/stdc++.h>
using namespace std;
const int N = 1e2;
int n, p;
int count1(int x) {
  int cnt = 0;
  for (int i = 0; i <= 30; ++i)
    if (x & (1 << i)) ++cnt;
  return cnt;
}
int mxcount(int x) {
  for (int i = 30; i >= 0; --i)
    if (x & (1 << i)) return i + 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> p;
  if (p >= 0) {
    n -= p;
    for (int i = 0; i <= N && n > 0; ++i) {
      int cnt = count1(n);
      if (cnt <= i + 1 && mxcount(n) >= i + 1) {
        cout << (i + 1) << endl;
        return 0;
      }
      n -= p;
    }
  } else {
    n -= p;
    for (int i = 0; i <= N; ++i) {
      int cnt = count1(n);
      if (cnt <= i + 1 && mxcount(n) >= i + 1) {
        cout << (i + 1) << endl;
        return 0;
      }
      n -= p;
    }
  }
  cout << -1 << endl;
}
