main = do m' <- getLine let m = read m' :: Integer print $ (2017 + (2017 * 2017) ^ 2017) `mod` m