#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
long long n, p;
int a[N];
vector<int> e[N];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void INIT() {}
void solve() {
  INIT();
  for (int i = 1; i <= 60; i++) {
    long long res = n - i * p;
    long long tmp = res;
    if (res <= 0) {
      break;
    }
    int cnt = 0;
    while (res) {
      cnt += (res % 2);
      res /= 2;
    }
    if (cnt <= i && i <= tmp) {
      cout << (i) << '\n';
      return;
    }
  }
  cout << (-1) << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> p) {
    solve();
  }
  return 0;
}
