#include <bits/stdc++.h>
using namespace std;
const int MAX = 100 * 1000 + 5;
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = 1LL * INF * INF;
const int MOD = INF;
const double PI = acos(-1.);
int main() {
  ios_base::sync_with_stdio(0);
  int n, p;
  cin >> n >> p;
  int ans = INF;
  for (int k = (1); k < (200); ++k) {
    long long tmp = n - k * p;
    long long x = tmp;
    if (tmp < 0) continue;
    int cnt = 0;
    while (tmp) {
      cnt += tmp % 2;
      tmp /= 2;
    }
    if (cnt <= k && k <= x) ans = min(ans, k);
  }
  if (ans == INF) ans = -1;
  cout << ans;
  return 0;
}
