fn gcd(a: usize, b: usize) -> usize { if b == 0 { a } else { gcd(b, a % b) } } fn run() { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let a: usize = it.next().unwrap().parse().unwrap(); let b: usize = it.next().unwrap().parse().unwrap(); if gcd(a, b) > 1 { println!("-1"); } else { let mut ans = a * b; for x in 1..=(a * b) { for i in 1..=(x / a) { if (x - i * a) % b == 0 { ans -= 1; break; } } } println!("{}", ans); } } fn main() { run(); }