#include <iostream>
using namespace std;

// Author: Nayaka Ghana Subrata

// 13
// 1 1 0 1
// (13, 1)
// -> 1 (tag) 1 (tag) 0 (skip) 1 (tag) = 3

int hitungNomorBit(int angka, int nomorBit){
	if (nomorBit != 0 && nomorBit != 1) return -1;
	int res = 0;
	
	while (angka > 0){
		// here, we can extract then shift to iterate the bits, so like take one and shift
		if ((angka & 1) == nomorBit) res++;
		angka >>= 1;
	}
	return res;
}


int main() {
	int angka, nomorBit;
	cin >> angka >> nomorBit;
	
	int res = hitungNomorBit(angka, nomorBit);
	
	// here, if the counted bit sum is none then it will return -1 that represents the null
	cout << res << endl;
	return 0;
}