#include #include #include using lint = long long; void solve() { lint a, b; std::cin >> a >> b; auto s = a + b; std::vector cs; for (lint p = 1; p * p <= s; ++p) { if (s % p != 0) continue; cs.push_back(p); cs.push_back(s / p); } std::sort(cs.begin(), cs.end()); for (auto c : cs) { if ((a + c) % b == 0 && (b + c) % a == 0) { std::cout << c << std::endl; return; } } std::cout << -1 << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }