fn main() { let mut m = String::new(); std::io::stdin().read_line(&mut m).ok(); let m: u64 = m.trim().parse().unwrap(); let mut product = 1; let mut b = (2017 * 2017) % m; let mut pow = 2017; while pow > 0 { if pow & 1 == 1 { product *= b; product %= m; } b *= b; b %= m; pow >>= 1; } println!("{}", (2017 + product) % m); }