import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) inf=float("inf") Dist=[inf]*(n+1) def popcount(x): x=x-((x>>1)&0x5555555555555555) x=(x&0x3333333333333333)+((x>>2)&0x3333333333333333) x=(x+(x>>4))&0x0f0f0f0f0f0f0f0f x=x+(x>>8) x=x+(x>>16) x=x+(x>>32) return x&0x0000007f Dist[1]=1 import collections S=collections.deque() S.append(1) while S: s=S.popleft() ss=popcount(s) if s+ss<=n and Dist[s+ss]==inf: Dist[s+ss]=Dist[s]+1 S.append(s+ss) if s-ss>=1 and Dist[s-ss]==inf: S.append(s-ss) Dist[s-ss]=Dist[s]+1 print(-1 if Dist[n]==inf else Dist[n])