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 nh in [h-m,h+m]: if -1 < nh < N and v[nh] > c: Q.append(nh) v[nh] = c else: print -1