#include long p(long x,long n,long m) { long r; if(1>n)return 1; r=p(x*x%m,n/2,m); if(n%2)r=r*x%m; return r; } int main(void) { long m; scanf("%ld",&m); printf("%ld",(2017+p(2017,2017,m)*p(2017,2017,m)%m)%m); return 0; }