n=2017,m,i;main(s){for(scanf("%d",&m);i++<2*n;s=s*n%m);i=!printf("%d",(s+n)%m);}