def ascan; gets.split.map(&:to_i);end def solve(x, y, depth=0) return nil if depth > 4 return 0 if x == y a = solve(y, x, depth+1) b = solve(x+y, x-y, depth+1) return nil if !a && !b return (a||b)+1 if !a || !b return [a,b].min+1 end while cin = gets x,y = cin.split.map(&:to_i) p solve(x,y) || -1 end