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

const int N=500;
int n,mod,xn[N];
long long dp[N*N];

#define id(x,y) *(xn+x)+y

int main(){
	cin>>n>>mod;
	dp[id(1,1)]=1;
	for(int i=2;i<=n;++i)
		xn[i]=xn[i-1]+n;
	xn[n+2]=(xn[n+1]=xn[n]+n)+n;
	for(int i=1;i<n;i++){
	  long long a=(dp[id(i,1)]<<1)%mod;
	  dp[id(i+1,2)]+=a;
	  dp[id(i+1,1)]+=a;
	  dp[id(i+2,1)]+=a;	  
	  for(int j=2;j<=n;j++){
		long long a=dp[id(i,j)]*(j-1)%mod,b=(dp[id(i,j)]*j<<1)%mod;
		dp[id(i+1,j+1)]+=dp[id(i,j)]*(j+1)%mod;
		dp[id(i+3,j-1)]+=a;
		dp[id(i+2,j-1)]+=a<<1;
		dp[id(i+1,j)]+=b;
		dp[id(i+2,j)]+=b;
	  }
	}
	  
	cout<<dp[id(n,1)]%mod<<endl;
} 