fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let mut l: usize = itr.next().unwrap().parse().unwrap(); let mut r: usize = itr.next().unwrap().parse().unwrap(); let mut c: usize = itr.next().unwrap().parse().unwrap(); let mut ans: usize = 1000; for i in l..=std::cmp::min(l + 999, r) { ans = std::cmp::min(ans, (1000 - i * c % 1000) % 1000) } println!("{}", ans); }