#include int main(){ int A, B; std::cin >> A >> B; if(std::gcd(A, B) != 1){ std::cout << -1 << std::endl; }else{ int N = std::lcm(A, B); std::vector check(N+1, 1); check[0] = 0; for(int x = 0; x <= B; ++x){ for(int y = 0; y <= A; ++y){ if(A*x+B*y <= N) check[A*x+B*y] = 0; } } int ans = std::count(check.begin(), check.end(), 1); std::cout << ans << std::endl; } return 0; }