m=gets.to_i b=(2017*2017)%m d=1%m c=2017 while c>0 if c%2==1 then d=(d*b)%m end b=(b*b)%m c=c/2 end puts (2017+d)%m