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