m = int(input()) x = 2017 + (2017 * 2017)**2017 print(x % m)