#include<bits/stdc++.h>
using namespace std;

int n,mod,f[5010][5010],x,y,s1[5010][5010],s2[5010][5010];

int main()
{
	scanf("%d%d",&n,&mod),x=1,y=0;
	if (n==2) return printf("3\n"),0;
	for (int i=1; i<=n; i++) f[i][n-i]=1;
	for (int j=1; j<=n; j++)
	{
		s2[j][n-j]=f[j][n-j];
		for (int k=n-j-1; k>=0; k--) s2[j][k]=(s2[j][k+1]+f[j][k]>=mod?s2[j][k+1]+f[j][k]-mod:s2[j][k+1]+f[j][k]);
		s1[j][n-j]=s2[j][n-j];
		for (int k=n-j-1; k>=0; k--) s1[j][k]=(s1[j][k+1]+s2[j][k]>=mod?s1[j][k+1]+s2[j][k]-mod:s1[j][k+1]+s2[j][k]);
	}
	for (int i=2,nw=n/(i-1); i<=n+1>>1; i++,nw=n/(i-1))
	{
		for (int j=1; j<=n; j++)
			for (int k=0; k<=nw&&j+k<=n; k++) f[j][k]=s1[j+k][k];
		for (int j=1,lim; j<=n; j++)
		{
			lim=min(n-j,nw);
			s2[j][lim]=f[j][lim];
			for (int k=lim-1; k>=0; k--) s2[j][k]=(s2[j][k+1]+f[j][k]>=mod?s2[j][k+1]+f[j][k]-mod:s2[j][k+1]+f[j][k]);
			s1[j][lim]=s2[j][lim];
			for (int k=lim-1; k>=0; k--) s1[j][k]=(s1[j][k+1]+s2[j][k]>=mod?s1[j][k+1]+s2[j][k]-mod:s1[j][k+1]+s2[j][k]);
		}
	}
	int ans=0;
	for (int j=1; j<=n; j++) 
		if (n&1) ans=(ans+s2[j][0])%mod;
		else ans=(ans+s1[j][0])%mod;
	printf("%d\n",ans);
	return 0;
}