def bitcnt(N): cnt = 0 while N != 0: if N % 2 == 1: cnt += 1 N = N // 2 return cnt N = int(input()) loc = 1 queue = [(1,1)] list = {1:1} while True: loc = queue[0][0] cnt = queue[0][1] + 1 mov = bitcnt(loc) if loc + mov <= N: if loc + mov not in list: list[loc + mov] = cnt queue.append((loc + mov,cnt)) if loc - mov >= 1: if loc - mov not in list: list[loc - mov] = cnt queue.append((loc - mov,cnt)) queue.pop(0) if queue == []: break #print(list) if N not in list: print(-1) else: print(list[N])