def Bit_sugorogu2(): N = int(input()) List = [] masu = 1 cnt = 1 while(True): List.append(masu) binary = bin(masu) num = binary.count("1") if(masu + num > N): break masu += num cnt += 1 print(masu) if(masu == N): return cnt else: now_masu = 0 while(now_masu != 1): now_masu = masu now_cnt = cnt + 1 binary = bin(now_masu) num = binary.count("1") usiro_masu = masu - num while(usiro_masu < N): if(usiro_masu in List): break List.append(usiro_masu) binary = bin(usiro_masu) num = binary.count("1") usiro_masu += num now_cnt += 1 if(usiro_masu == N): return now_cnt cnt += 1 masu -= num return -1 if __name__ == "__main__": print(Bit_sugorogu2())