#include<stdio.h>
#define ll long long

const int N=407;

int n;
ll dp[N][N],Mod,fac[N],inv[N],pw[N];

ll qpow(ll x,int y){
	ll ret=1;
	while(y){
		if(y&1) ret=ret*x%Mod;
		x=x*x%Mod,y>>=1;
	}
	return ret;
}

inline int min(int x,int y){return x<y? x:y;}
inline ll C(int x,int y){return x<y? 0:fac[x]*inv[y]%Mod*inv[x-y]%Mod;}

int main(){
	scanf("%d%d",&n,&Mod);
	fac[0]=pw[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%Mod,pw[i]=pw[i-1]*2%Mod;
	inv[n]=qpow(fac[n],Mod-2);
	for(int i=n-1;~i;i--) inv[i]=inv[i+1]*(i+1)%Mod;
	dp[1][1]=1;
	for(int i=2;i<=n;i++){
		dp[i][i]=pw[i-1];
		for(int j=2;j<i;j++){
			int rg=min(i-1,j);
			for(int k=2;k<=rg;k++)
				dp[i][j]=(dp[i][j]+pw[k-2]*C(j,k-1)%Mod*dp[i-k][j-k+1]%Mod)%Mod;
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=(ans+dp[n][i])%Mod;
	printf("%lld",ans);
}