import re def CountBit(n): ss = 0 s = re.sub(r'\D', "", bin(n)) for i in s: ss += int(i) return ss End = int(input()) Position = 1 Before = [] Count = 1 while Position != End: if Position in Before: Count = -1 break else: Before.append(Position) Step = CountBit(Position) if Position + Step > End: Position -= Step else: Position += Step Count += 1 print(Count)