N=gets.to_i current=1 count=0 while current != N && N != 4 do count+=1 i = current.to_s(2).count("1").to_i if current+i > N current -= i else current += i end end if N==4 p "-1" else p count + 1 end