N = int(input()) if N == 1: print(1) else: num = 1 trace = [1] result = [1] while trace != []: b = bin(num) i = b.count('1') if num + i < N: if num + i not in result: num = num + i trace.append(num) result.append(num) elif num + i in result and num - i not in result: num = num - i trace.append(num) result.append(num) elif num + i in result and num - i in result: del trace[-1] if trace == []: print(-1) break else: num = trace[-1] elif num + i > N: if num - i not in result: num = num - i trace.append(num) result.append(num) else: del trace[-1] if trace == []: print(-1) break else: num = trace[-1] elif num + i == N: num = num + i trace.append(num) result.append(num) print(len(trace)) break