a, b = gets.split.map(&:to_i) if a > b a, b = b, a end if a == b || 2*a == b puts "#{a}" elsif 3*a == b puts "#{2*a}" else puts "-1" end