def modpow(x,n,mod): ret = 1 while n > 0: if n % 2 == 1: ret = ret * x % mod x = x * x % mod n /= 2 return ret m = int(input()) #print((2017+modpow(2017*2017,2017,m)) % m) print((2017+(2017*2017)**2017) % m)