#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
using namespace std;
typedef long long ll;
const int maxn=510;
const int k=8;
int P[]={2,3,5,7,11,13,17,19};
int n,p,bel[k],A[2][maxn],xp2[maxn];
ll dfs(int cur) {
if(cur==k) {
memset(A,0,sizeof(A));
ll xp=1;
rep(i,2,n) {
int m=i,ok1=0,ok2=0;
rep(j,0,k-1) if(m%P[j]==0) {
ok1|=(bel[j]!=1);
ok2|=(bel[j]!=2);
while(m%P[j]==0) m/=P[j];
}
if(!ok1) A[0][m]++;
if(!ok2) A[1][m]++;
}
rep(i,20,n) (xp*=(xp2[A[0][i]]+xp2[A[1][i]]+p-1)%p)%=p;
(xp*=xp2[A[0][1]+A[1][1]])%=p;
return xp;
}
ll ans=0;
bel[cur]=1;(ans+=dfs(cur+1))%=p;
bel[cur]=2;(ans+=dfs(cur+1))%=p;
bel[cur]=0;(ans-=dfs(cur+1))%=p;
return (ans+p)%p;
}
int main() {
scanf("%d%d",&n,&p);xp2[0]=1;
rep(i,1,n) xp2[i]=2*xp2[i-1]%p;
printf("%lld\n",dfs(0));
return 0;
}