#yuki_487 m=int(raw_input()) n=2017 res=n+pow(n*n,n,m) res=res%m print res