#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 505;

int n, mod;
ll fac[N], inv[N], f[N][N], two[N];

ll bigMod (ll a, ll e) {
  if (e == -1) e = mod - 2;
  ll ret = 1;
  while (e) {
    if (e & 1) ret = ret * a % mod;
    a = a * a % mod, e >>= 1;
  }
  return ret;
}

int main() {
  cin >> n >> mod;
  fac[0] = two[0] = 1;
  for (int i = 1; i < N; ++i) two[i] = 2 * two[i - 1] % mod;
  for (int i = 1; i < N; ++i) fac[i] = i * fac[i - 1] % mod;
  inv[N - 1] = bigMod(fac[N - 1], -1);
  for (int i = N - 1; i; --i) inv[i - 1] = i * inv[i] % mod;
  f[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i; ++j) {
      for (int k = 1; k <= i; ++k) {
        f[i][j] += f[i - k][j - 1] * inv[k] % mod * two[k - 1];
        f[i][j] %= mod;
      }
    }
  }
  ll ans = 0;
  for (int k = 1; k <= n; ++k) {
    ll add = fac[n - k + 1] * f[n - k + 1][k] % mod;
    // cerr << add << '\n';
    ans += add, ans %= mod;
  }
  cout << ans << '\n';
  return 0;
}

