m = int(input()) if m == 1 or m == 2017: print("0") exit() print((2017 + pow(2017, 4034, m)) % m)