n=gets.to_i g=2017 x=y=g*g (g-1).times do y*=x y%=n end p (y+g)%n