use std::io::*; fn gcd(a: u64, b: u64) -> u64 { if b == 0 { return a; } gcd(b, a % b) } fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let a: u64 = itr.next().unwrap().parse().unwrap(); let b: u64 = itr.next().unwrap().parse().unwrap(); let c = gcd(a, b); if c != 1 { println!("-1",) } else { let mut ans = a / c * b; let lcm = a / c * b; for x in 0..b { for y in 0..a { if a * x + b * y <= lcm { ans -= 1; } } } println!("{}", ans); } }