#include using namespace std; int gcd(int x, int y){ if(y>x) swap(x,y); if(y==0) return x; return gcd(x%y,y); } int c[20010]; int main(){ int i,j,a,b,ans = 0; cin >> a >> b; if(gcd(a,b)!=1){ cout << -1 << endl; return 0; } for(i=1;i<=a*b;i++){ c[i] = 1; } for(i=0;i<=b;i++){ for(j=0;j<=a;j++){ c[a*i + b*j] = 0; } } for(i=1;i<=a*b;i++){ ans += c[i]; } cout << ans << endl; }