# coding: utf-8 def count_1(n): count = 0 flg = True while (flg): mod = n % 2 if mod==0: pass if mod==1: count += 1 if (mod==n): flg = False n = int(n / 2) return count # Run the main function if called from the command line if __name__ == "__main__": # 標準入力から一行分を読み出し、文字列として格納する。 first = input() # 読み込んだ文字列をスペースで分割する #split_first = first.split() # それぞれをint型に変換する N = int(first) # 慣れてくると この一行でよい # A, B = map(int, input().split()) # 参考: リストを読む際はlist()で覆ってやらないといけない # L = list(map(int, input().split())) #2行目を読み込む #S = input() # 標準出力に書き出す。 # カンマで区切るとスペースで分割してくれるので楽です。 #print(A + B, S) target_list = [N] cand_list = [] count = 1 flg = True while(flg): count += 1 for target in target_list: for i in range(1, 14): t_pi = target + i if target+i <= N: if (t_pi - count_1(t_pi) == target): cand_list.append(t_pi) t_mi = target - i if t_mi >= 1: if (t_mi + count_1(t_mi) == target): cand_list.append(t_mi) print (cand_list) # 終了判定 if N==1: count = 1 flg = False elif len(cand_list)==0: count = -1 flg = False else: for i in cand_list: if i==1: flg = False else: pass target_list = cand_list cand_list = [] print (count)