M = int(input()) if M in (1, 2017): print(0) else: print((2017 + pow(2017 * 2017, 2017, M)) % M)