use std::collections::HashSet; use std::cmp::{max, min}; fn gcd(a: usize, b: usize) -> usize { if a % b == 0 { return b; } gcd(b, a % b) } fn main() { let mut ab: String = String::new(); std::io::stdin().read_line(&mut ab).ok(); let ab: Vec = ab.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let a: usize = ab[0]; let b: usize = ab[1]; let gcd: usize = gcd(max(a, b), min(a, b)); if gcd > 1 { println!("{}", -1); } else { let lcm: usize = a * b; let aa: Vec = (0..=b).map(|i| a*i).collect(); let bb: Vec = (0..=a).map(|i| b*i).collect(); let mut abs: HashSet = HashSet::new(); for i in aa.iter() { for j in bb.iter() { if i + j <= lcm { abs.insert(i+j); } } } let result: usize = lcm + 1 - abs.len(); println!("{}", result); } }