a,c,n,m;main(b){for(scanf("%d%d",&n,&m);--n;a=b,b=c)c=(a+b)%m;printf("%d",a);}