import queue import sys n=int(input()) q=queue.Queue() q.put([1,1,[False]*(n+1)]) while not q.empty(): now=q.get() if now[0]==n: print(now[1]) sys.exit() temp=now[0] ad=0 while (temp > 0): if temp & 1: ad += 1 temp = temp >> 1 next=now[0]+ad if next<=n and not now[2][next]: now[2][next]=True q.put([next,now[1]+1,now[2]]) next=now[0]-ad if next>0 and not now[2][next]: now[2][next]=True q.put([next,now[1]+1,now[2]]) print(-1)