#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 0;
int n, p;
void init();
void input();
void work();
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() { cin >> n >> p; }
void work() {
  for (int i = 1;; ++i) {
    int cur = n - i * p;
    if (i <= cur) {
      if (__builtin_popcount(cur) <= i) {
        cout << i << endl;
        return;
      }
    } else if (p >= 0) {
      cout << -1 << endl;
      return;
    }
  }
}
