def solve(): m = int(input()) x = (2017 * 2017) ** 2017 x += 2017 print(x % m) if __name__=="__main__": solve()