from math import inf, log10, floor, log2 def main(): N = int(input()) two_pow_over_N = 2 ** (floor(log2(N))+1) table = [inf for _ in range(two_pow_over_N)] for idx in range(floor(log2(N))+2): table[2**idx - 1] = idx for idx in range(2, floor(log2(N))+2): for mid_idx in reversed(range(2**(idx-1)+1, 2**idx)): if mid_idx % 2 != 0: table[mid_idx-1] = table[mid_idx] + 1 else: table[mid_idx-1] = min( table[mid_idx], table[mid_idx // 2 - 1] ) + 1 print(table[N-1]) if __name__ == "__main__": main()