M = int(input()) x = (2017*2017)%M ans = 1 for _ in [0]*2017: ans = (ans*x)%M print((ans+2017)%M)