M = int(input()) ans = (2017 + pow(2017, 2017*2, M)) % M print(ans)