#include <bits/stdc++.h>
int n, p;
void solve() {
  scanf("%d %d", &n, &p);
  int ans = 0;
  while (1) {
    n -= p;
    ans++;
    if (n < ans) {
      ans = -1;
      break;
    }
    if (ans >= __builtin_popcount(n)) break;
  }
  printf("%d\n", ans);
}
int main() { solve(); }
