import sys input=lambda: sys.stdin.readline().rstrip() m=int(input()) x=2017+pow(2017**2,2017,m) print(x%m)