targetN = int(input());
kakunin = 1;
result = 1;
moji = "";
mathu = 0;
tyokau = 0;
tmpnum = 0;
tmpcounter = 0;

while targetN != kakunin and result != -1:
	mathu = 0;
	data = kakunin;
	while data >= 1:
		if data % 2 == 1:
			mathu = mathu + 1;
		
		data = int(data/2);
		
	
	if targetN > 1:
	    kakunin = kakunin + mathu;

	if targetN > kakunin or targetN == kakunin:
		result = result + 1;
	else:
		kakunin = kakunin - 2 * mathu;
		if tmpcounter == 0:
		    tmpnum = kakunin;
		    tmpcounter= tmpcounter+1;
		result = result + 1;
		tyokau = tyokau + 1;
		if tyokau > 1 and tmpnum ==kakunin:
			result = -1;
			
	

print(result);