module Yuki open System let [] YEAR = 2017 let solve m = let square = YEAR * YEAR let rec f acc = function | 1 -> (acc * square) % m | n -> f ((acc * square) % m) (n - 1) (2017 + (f 1 2017)) % m let M = int <| Console.ReadLine() solve M |> Console.WriteLine