n = int(input()) pls = [i+1 for i in range(n)] bls = [str(bin(i+1)).count('1') for i in range(n)] pp = 1 cnt = 1 while True: tp = pp + bls[pp-1] if tp == n: cnt += 1 print(cnt) break elif tp < n: pp += bls[pp-1] cnt += 1 try: pls.remove(pp) except: print(-1) break elif tp > n: pp -= bls[pp-1] cnt += 1 try: pls.remove(pp) except: print(-1)