# coding: utf-8 n = int(input()) position = 1 history = [] result = -1 while True: history.append(position) if position == n: result = len(history) break steps = str(format(position, 'b')).count('1') if position + steps > n: position -= steps else: position += steps if position in history: break print(result)