def step(num): res = 0 if num in step.res_dict: return step.res_dict.get(num) while True: res += num % 2 num //= 2 if num == 0: break step.res_dict[num] = res return res 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 > N + N // 2: print(-1) break