import sequtils import strutils import algorithm proc divisor(n : int) : seq[int] = result = newSeq[int](0) var n = n var i = 1 while i * i <= n: if n mod i == 0: result.add(i) if i * i != n: result.add(n div i) i += 1 result.sort() var ab = stdin.readLine.split.map(parseInt) var (a, b) = (ab[0], ab[1]) var n = a + b var ans = -1 for c in divisor(n): if c != a and c != b: if ((c + a) mod b == 0 ) and ((c + b) mod a == 0): ans = c echo ans