#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, P;
    std::cin >> n >> P;
    std::vector<std::vector<int>> f(n + 1, std::vector<int>(n + 1));
    std::vector<int> bin(n, 1), fac(n, 1), ifac(n, 1);
    auto ksm = [&](int x, int k) -> int {
        int rnt = 1;
        while(k) {
            if(k & 1) rnt = 1ll * rnt * x % P;
            x = 1ll * x * x % P; k >>= 1;
        } return rnt;
    };
    for(int i = 1; i < n; i++) fac[i] = 1ll * fac[i - 1] * i % P;
    ifac[n - 1] = ksm(fac[n - 1], P - 2);
    for(int i = n - 2; i >= 0; i--) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % P;
    for(int i = 1; i < n; i++) bin[i] = bin[i - 1] * 2 % P;
    f[1][1] = 1;
    f[2][2] = 2;
    for(int i = 3; i <= n; i++) {
        for(int j = 1; j < i; j++) {
            for(int k = 1; k <= i - 2; k++) {
                int del = j - i + k + 1;
                if(del < 0) continue;
                int d = 1ll * ifac[del] * fac[j] % P * ifac[i - k - 1] % P;
                f[i][j] = (f[i][j] + 1ll * f[k][del] * d % P * bin[i - k - 2] % P) % P;
            }
        }
        f[i][i] = bin[i - 1];
    }
    int ans = std::accumulate(f[n].begin(), f[n].end(), 0ll) % P;
    std::cout << ans << std::endl;
    return 0;
}