m=int(input()) c=2017%m d=1 for i in range(1,2018): d*=c**2 if d>m: d=d%m print((2017+d)%m)