m = int(input()) a = 2017 % m b = (a * a) % m c = b**2017 % m d = (a + c) % m print(d)