#include #define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i) #define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define clr(ar, val) memset(ar, val, sizeof(ar)) #define sbp(p, n) rep(i, n) { int a, b; scanf("%d %d", &a, &b); p[i] = make_pair(a, b); } template bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int gcd(long a,long b){return b?gcd(b,a%b):a;} using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair P; typedef long double ld; int main(void) { long a, b, k; vector yakusu; cin >> a >> b; for(int i = 1; i * i <= a + b; i++){ if((a + b) % i == 0){ yakusu.push_back(i); } } for(long m : yakusu){ if((a + b) % m == 0 && (a + m) % b == 0 && (b + m) % a == 0){ cout << m << endl; return 0; } } cout << -1 << endl; return 0; }