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, mut b) = (1, 0); (2..n[0]).for_each(|_| (a, b) = ((a + b) % n[1], a)); println!("{}", a) }