#include <bits/stdc++.h>
using namespace std;
int n, p;
bool chk(int x, int k) {
  if (x < 1)
    return 0;
  else {
    int a = 0;
    vector<int> st(31, 0);
    for (int i = 30; i >= 0; i--) {
      while (x >= 1 << i) {
        st[i]++;
        x -= 1 << i;
        a++;
      }
    }
    for (int i = 30; i > 0; i--) {
      if (a + st[i] < k) {
        a += st[i];
        st[i - 1] += st[i] * 2;
        st[i] = 0;
      } else if (a < k) {
        a = k;
        break;
      }
    }
    return (a == k);
  }
}
int main() {
  cin >> n >> p;
  int ans = 1e9;
  for (int i = 1; i < 31; i++) {
    if (chk(n - p * i, i)) {
      ans = i;
      break;
    }
  }
  if (ans == 1e9)
    cout << -1;
  else
    cout << ans;
}
