import math from heapq import heappush, heappop N = int(raw_input()) heap = [] heappush(heap,(1,1)) arrived = [False for i in range(N+1)] while len(heap)>0: dist, num = heappop(heap) if arrived[num]: continue if num == N: print dist exit() arrived[num]=True tmp = num cnt = 0 while tmp != 0: tmp &= tmp-1 cnt+=1 if num-cnt > 0 and arrived[num-cnt] ==False: heappush(heap,(dist+1,num-cnt)) if num+cnt <= N and arrived[num+cnt] ==False: heappush(heap,(dist+1,num+cnt)) print -1