import math def bitcount(n): cnt=0 while n!=0: cnt+=n%2 n=math.floor(n/2) return cnt N=int(input()) cnt=1 cntF=False flag=[False for i in range(N+1)] flag[1]=True stack=[1] p=0 i=0 while len(stack)!=0 and i!=N: p = stack.pop(0) flag[p]=True for i in [p+bitcount(p),p-bitcount(p)]: if 1<=i and i<=N and flag[i]==False: stack.append(i) cntF=True if i == N: break if cntF: cnt+=1 cntF=False if i==N: print(cnt) elif N == 1: print(1) else: print(-1)