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(); println!( "{}", if n[0] > n[1] { 2 * 10u64.pow(9) - n[1] - 1 } else { n[1] - 2 } ); }