#include using namespace std; int64_t gcd(int64_t a, int64_t b){ return b==0 ? a : gcd(b, a%b); } int main(){ int A, B; cin >> A >> B; if(gcd(A, B) > 1){ cout << -1 << endl; return 0; } bitset<20000> dp; dp[0] = 1; int ans = 0; for(int i=0; i<=A*B; i++){ if(dp[i]){ dp[i+A] = dp[i+B] = 1; }else{ ans++; } } cout << ans << endl; return 0; }