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 mut a = 1000; for i in n[0]..=n[1].min(n[0] + 999) { a = a.min((1000 - i * n[2] % 1000) % 1000); } println!("{a}") }