#include #include #include #include #include #include #include using namespace std; typedef long long int ll; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int a,b; cin >> a >> b; if(__gcd(a,b)!=1){ cout << -1 << endl; return 0; } int ans=0; for(int i=1;i<=100*1000;i++){ bool ok=0; for(int j=0;j<=1000;j++){ if(i-a*j>=0){ if((i-a*j)%b==0){ ok=1; break; } } else break; } if(!ok){ ans++; } } cout << ans << endl; }