#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	vector <vl> c(n + 1, vl (n + 1, 0));
	for (ll i = 1; i <= n; i++)
		c[i][0] = 1;
	c[1][1] = 1;
	for (ll i = 2; i <= n; i++) {
		for (ll j = 1; j <= i; j++)
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % m;
	}
	vl ptwo(n + 1);
	ptwo[0] = 1;
	for (ll i = 1; i <= n; i++)
		ptwo[i] = (ptwo[i - 1] * 2LL) % m;
	vector <vl> dp(n + 2, vl (n + 2, 0));
	dp[0][0] = 1;
	for (ll i = 0; i <= n; i++) {
		for (ll j = 0; j <= i; j++) {
			for (ll k = 1; k <= n; k++) {
				if (i + k >= n + 1)
					break;
				ll add = (ptwo[k - 1] * dp[i][j]) % m;
				add = (add * c[k + j][k]) % m;
				dp[i + k + 1][j + k] = (dp[i + k + 1][j + k] + add) % m;
			}
		}
	}
	ll ans = 0;
	for (ll i = 0; i <= n; i++)
		ans = (ans + dp[n + 1][i]) % m;
	cout << ans;
}
