def step(num): return sum(list(map(int, list(format(num, 'b'))))) step.res_dict = {} N = int(input()) m = 1 cnt = 0 while True: next = step(m) cnt += 1 if N < m + next: m -= next elif N > m + next: m += next else: m += next cnt += 1 print(cnt) break if cnt > 2*N: print(-1) break