long x,i,t,m;main(y){for(scanf("%d%d",&i,&m);--i;x=y,y=t)t=(x+y)%m;printf("%d",x);}