import sequtils,strutils,strscans,algorithm,math,future,sets,queues,tables template get():string = stdin.readLine() template times(n:int,body:untyped): untyped = (for _ in 0.. N close[1] = 1 while open.len > 0: let n = open.pop() depth = close[n] if n == N: echo depth quit() let diff = countBits32(n.int32) for succ in @[n + diff,n - diff]: if succ > N or succ < 1: continue if close[succ] == -1: close[succ] = depth + 1 open.enqueue(succ) echo -1