N=input();v=[N+1]*N;v[0]=1;Q=[0] while Q: h=Q.pop(0) if h==N-1:print v[h];break m=bin(h+1).count("1");c=v[h]+1 for n in[h-m,h+m]: if 0<=nc:Q+=[n];v[n]=c else:print -1