#include <bits/stdc++.h>
using namespace std;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args>
void my_dbg(Arg A, Args... B) {
  cout << ' ' << A;
  my_dbg(B...);
}
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int N = 1e6 + 2;
void solve() {
  int n, p;
  scanf("%d", &n);
  scanf("%d", &p);
  int k = 1;
  while (1) {
    int val = n - k * p;
    if (val < k) break;
    vi fa(41, 0);
    int cnt = 0;
    for (int i = 40; i >= 0; i--) {
      ll here = 1LL << i;
      if (val - here >= 0) {
        val -= here;
        fa[i] = 1;
        cnt++;
      }
    }
    for (int i = 40; i >= 1; i--) {
      if (cnt < k and fa[i]) {
        int mn = min(k - cnt, fa[i]);
        fa[i - 1] += 2 * mn;
        cnt += mn;
      }
    }
    if (cnt == k) {
      printf("%d\n", (int)(k));
      exit(0);
    }
    k++;
  }
  printf("%d\n", (int)(-1));
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
