modPow x y m = foldr (\_ acc -> mod (acc*x) m) 1 [1..y] main = readLn >>= print . (\n -> mod (modPow 2017 (2017*2) n + mod 2017 n) n)