N=int(input()) a=list(range(1,N+1)) b=[] c=[[1,1]] d=[] e=[] for i in range(1,N+1): b.append(int(bin(i).count('1'))) for i in c: if ((a[i[0]-1]+b[i[0]-1])in a)and(((a[i[0]-1]+b[i[0]-1])in e)==False): c.append([a[i[0]-1]+b[i[0]-1],i[-1]+1]) if ((a[i[0]-1]-b[i[0]-1])in a)and(((a[i[0]-1]-b[i[0]-1])in e)==False): c.append([a[i[0]-1]-b[i[0]-1],i[-1]+1]) e.append(a[i[0]-1]) d.append([a[i[0]-1],i[-1]]) if N in e: print(c[e.index(N)][-1]) else: print(-1)