#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define all(v) v.begin(), v.end()
ll n, p[401], m, comb[1001][1001], dp[401][401], ans;

ll go(ll a, ll b) {
	ll& ret = dp[a][b], x;
	if (ret != -1) return ret;
	if (a <= 0 || a <= b) return 0;
	if (b == 0) return ret = p[a - 1];
	
	ret = 0;
	for (int i = a - 2; i > 0; i--) {
		x = go(i, b - 1) * p[a - i - 2] % m;
		x *= comb[a - b][a - i - 1];
		ret += x % m; ret %= m;
	}
	return ret;
}

int main(void) {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n >> m;
	p[0] = 1;
	for (int i = 1; i <= n; i++) {
		p[i] = p[i - 1] * 2 % m;
	}

	for(int i = 0; i <= 1000; i++)
		for (int j = 0; j <= i; j++) {
			if (j == 0 || j == i) comb[i][j] = 1;
			else comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % m;
		}

	memset(dp, -1, sizeof(dp));
	for (int i = 0; i <= n; i++) {
		ans += go(n, i); ans %= m;
	}
	cout << ans;
	return 0;
}