import sys n=int(input());m=sys.maxsize;q=[1];d=[0,1]+[m]*(n-1) while(q): _=q.pop(0);c=bin(_).count('1');b=_-c;f=_+c if b>0 and d[b]>d[_]+1:d[b]=d[_]+1;q.append(b) if f<=n and d[f]>d[_]+1:d[f]=d[_]+1;q.append(f) print(d[-1] if d[-1]!=m else -1)