#include <bits/stdc++.h>
using namespace std;
using INT = long long;
int main() {
  INT n, p;
  cin >> n >> p;
  int id = -1;
  for (int i = 1; i <= 30; i++) {
    INT num = n;
    num -= p * i;
    if (__builtin_popcountll(num) > i) continue;
    if (num < i) continue;
    id = i;
    break;
  }
  cout << id << endl;
}
