def powmod(a, p): if p == 0: return 1 if p % 2 == 1: return a * powmod(a, p - 1) else: t = powmod(a, p / 2) return t * t M = input() print (2017 + powmod(2017 * 2017, 2017)) % M