#include using namespace std; int main(){ long A, B; cin >> A >> B; long N{A + B}; vector tapi, tape; { long i; for(i = 1; i * i <= N; ++i)if(N % i == 0){tapi.push_back(i); tape.push_back(N / i);} } reverse(tape.begin(), tape.end()); for(const auto i : tapi) if((A + i) % B == 0 && (B + i) % A == 0)return 0 & printf("%ld\n", i); for(const auto i : tape) if((A + i) % B == 0 && (B + i) % A == 0)return 0 & printf("%ld\n", i); puts("-1"); }