#include using namespace std; int main() { long long a,b;cin >> a >> b; if (min(a,b)==1) cout << 0 << endl; else if (__gcd(a,b)>1) cout << -1 << endl; else { long long count=a*b-1; for (int i=0;i<=a;i++) { for (int j=0;j<=b;j++) { if (i+j>0 && a*j+b*i