import kotlin.math.sqrt fun main() { val builder = StringBuilder() val (a, b) = readInputLine().split(" ").map { it.toInt() } var ans = -1 for (c in 1..sqrt((a + b).toDouble()).toInt() + 1) { if ((a + b) % c == 0 && c != a && c != b) { if ((a + c) % b == 0 && (b + c) % a == 0) { ans = c break } } val c2 = (a + b) / c if ((a + b) % c2 == 0 && c2 != a && c2 != b) { if ((a + c2) % b == 0 && (b + c2) % a == 0) { ans = c2 break } } } builder.appendln(ans) print(builder.toString()) } fun readInputLine(): String { return readLine()!! }