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