M=int(input()) X=(2017+pow(2017*2017,2017,M))%M print(X)