from collections import deque def main(): X, Y = map(int, input().split()) if X == Y: print(0) return initial_max = max(abs(X), abs(Y)) # Set a limit to avoid infinite expansion; 2^20 is arbitrary but large enough for given constraints LIMIT = initial_max * (2 ** 20) visited = set() q = deque() q.append((X, Y, 0)) visited.add((X, Y)) answer = -1 found = False while q: x, y, steps = q.popleft() if x == y: answer = steps found = True break # Apply Operation 1: Swap new_x1, new_y1 = y, x if (new_x1, new_y1) not in visited: if abs(new_x1) <= LIMIT and abs(new_y1) <= LIMIT: visited.add((new_x1, new_y1)) q.append((new_x1, new_y1, steps + 1)) # Apply Operation 2: X+Y and X-Y new_x2 = x + y new_y2 = x - y if (new_x2, new_y2) not in visited: if abs(new_x2) <= LIMIT and abs(new_y2) <= LIMIT: visited.add((new_x2, new_y2)) q.append((new_x2, new_y2, steps + 1)) print(answer if found else -1) if __name__ == "__main__": main()