#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
ll powmod(ll a,ll b) {ll res=1,mod=b+2; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

void solve() {
    ll n,M;
    cin >> n >> M;
    ll fac[n+1],invfac[n+1]; fac[0]=1; invfac[0]=1;
    for(ll i=1;i<=n;++i) {
        fac[i] = (fac[i-1]*1ll*i)%M;
        invfac[i] = powmod(fac[i],M-2);
    }
    vl F(n+1);  F[1] = 1;
    FOR(i,2,n+1) F[i] = (F[i-1]*2)%M;
    F0R(i,n+1) F[i] = (F[i]*1ll*invfac[i])%M;
    ll ans = 0; 
    vl g = F;
    FOR(k,1,1000) {
        if(2*k > n+1) break;
        ans = (ans + (g[n-k+1]*1ll*fac[n-k+1])%M)%M;
        vl r(n+1);
        for(int c=0;c<=n;++c) {
            for(int x=0;x<=c;++x) {
                r[c] = (r[c] + (g[x]*1ll*F[c-x])%M)%M;
            }
        }
        g=r;
    }
    cout << ans << '\n';
}


int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); 
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1,Tc=1;
    while(t--){
        solve();
    }
  return 0;
}