fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let n: Vec = s.split_whitespace().flat_map(str::parse).collect(); let x = (0..).find(|x| x % n[0] == n[2] && x % n[1] == n[3]); println!("{}", x.unwrap()); }