use std::str::{FromStr, SplitWhitespace}; use std::fmt::Debug; trait ReadExt { fn read(&mut self) -> T where ::Err: Debug; fn read_vec(&mut self, n: usize) -> Vec where ::Err: Debug, T: Debug; } impl<'a> ReadExt for SplitWhitespace<'a> { fn read(&mut self) -> T where ::Err: Debug, { if let Some(word) = self.next() { match word.parse::() { Ok(res) => { res } Err(e) => { panic!("Failed to parse '{}' as requested type: {:?}", word, e); } } } else { panic!("Failed to read: No more words available for parsing."); } } fn read_vec(&mut self, n: usize) -> Vec where ::Err: Debug, T: Debug, { let mut vec = Vec::with_capacity(n); for _ in 0..n { let element = self.read::(); vec.push(element); } vec } } fn main() { let stdin = std::io::read_to_string(std::io::stdin()).unwrap(); let mut stdin = stdin.split_whitespace(); let n = stdin.read::(); let b = stdin.read::(); for i in 0..b{ if (n*i)%b == 1 % b { println!("{:?}",i); return; } } println!("NaN"); }