M = int(input()) tmp = (2017*2017)%M X = 1 for i in range(2017): X = (X*tmp)%M X = (X + 2017)%M print(X)