#include using namespace std; using ll = long long; #define fi first #define se second int main(){ ll a,b; cin >> a >> b; for(ll c=1;c <= a+b;) { if((a+b)%c == (b+c)%a && (c+a)%b == (a+b)%c && (b+c)%a==0){ cout << c << endl; return 0; } if((a+c)%b!=0){ c+=b-(a+c)%b; }else if((b+c)%a!=0){ c+=a-(b+c)%a; }else{ c++; } } cout << -1 << endl; }