N=int(input()) A=2017%N B=(2017**2)%N #print(A) #print(B) C=B for i in range(2016): C=(C*B)%N print((A+C)%N)