#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  cin >> n >> p;
  if (n < p) {
    cout << -1;
    return 0;
  }
  int answer = 1000000000;
  int actions = 0;
  while (n > p) {
    n -= p;
    actions++;
    int number = n;
    int ones = 0;
    int bits = 0;
    while (number > 0) {
      ones += number % 2;
      number /= 2;
      bits++;
    }
    if (actions >= ones && bits >= actions) answer = min(answer, actions);
    if (actions == 32) break;
  }
  if (answer != 1000000000 && answer != 0)
    cout << answer;
  else
    cout << -1;
  return 0;
}
