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] list = {1:0} cnt = 0 while True: loc = queue[0] cnt += 1 mov = bitcnt(loc) if loc + mov <= N: if loc + mov not in list: list[loc + mov] = cnt queue.append(loc + mov) if loc - mov >= 1: if loc - mov not in list: list[loc - mov] = cnt queue.append(loc - mov) queue.remove(loc) if queue == []: break if N not in list: print(-1) else: print(list[N])