#include "bits/stdc++.h" using namespace std; typedef long long ll; #define INF (1<<30) #define INFLL (1ll<<60) typedef pair P; typedef pair E; #define MOD (1000000007ll) #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a += b; a %= MOD; } int main(void){ ll a,b,c,s,i; cin >> a >> b; s = (a+b); for(i=1ll; i*i<=s; ++i){ if(s%i){ continue; } c = i; if(!(a==b || b==c || c==a || (a+b)%c || (b+c)%a || (c+a)%b )){ cout << c << endl; return 0; } c = s/i; if(!(a==b || b==c || c==a || (a+b)%c || (b+c)%a || (c+a)%b )){ cout << c << endl; return 0; } } cout << -1 << endl; return 0; }