#include #include #include #include typedef int32_t i32; typedef int64_t i64; #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) void run (void) { i32 a, b; scanf ("%" SCNi32 "%" SCNi32, &a, &b); i32 x = MIN(a, b); i32 y = MAX(a, b); i32 c = y - x; if ((x + y) % c == 0 && (c + y) % x == 0) { printf ("%" PRIi32 "\n", c); return; } c = x + y; if (((i64) c + x) % y == 0 && ((i64) c + y) % x == 0) { printf ("%" PRIi32 "\n", c); return; } puts("-1"); } int main (void) { run(); return 0; }