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

void __print(int x) { cerr << x; }
void __print(int64_t x) { cerr << x; }
void __print(uint32_t x) { cerr << x; }
void __print(uint64_t x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V> &x) { cerr << '('; __print(x.first); cerr << ", "; __print(x.second); cerr << ')'; }
template<typename T>
void __print(const T &x) { int f = 0; cerr << '{'; for(auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}"; }
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) { __print(t); if(sizeof...(v)) cerr << ", "; _print(v...); }

#define debug(x...) cerr << " > [" << #x << "] = ["; _print(x)

const int MaxM = 405;

int64_t dp_0[3][MaxM][MaxM]; /// [bez, po, przed][-2, -1, cur][cnt-1][k-1]
int64_t dp_1[3][MaxM][MaxM]; /// [bez, po, przed][-2, -1, cur][cnt-1][k-1]
int64_t dp_2[3][MaxM][MaxM]; /// [bez, po, przed][-2, -1, cur][cnt-1][k-1]

int64_t pref_0[3][MaxM][MaxM];
int64_t pref_1[3][MaxM][MaxM];
int64_t pref_2[3][MaxM][MaxM];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int n;
    int64_t M;
    cin >> n >> M;
    dp_0[0][1][1] = 1;

    dp_1[1][2][2] = 1;
    dp_2[1][2][1] = 1;

    auto sum_0 = [&](int i, int cnt, int l, int r) {
        if(i < 6) {
            int64_t sum = 0;
            for(int j = l; j <= r; j++) {
                sum = (sum + dp_0[i % 3][cnt][j]) % M;
            }
            return sum;
        }
        else return pref_0[i % 3][cnt][r+1] - pref_0[i % 3][cnt][l];
    };

    auto sum_1 = [&](int i, int cnt, int l, int r) {
        if(i < 6) {
            int64_t sum = 0;
            for(int j = l; j <= r; j++) {
                sum = (sum + dp_1[i % 3][cnt][j]) % M;
            }
            return sum;
        }
        else return pref_1[i % 3][cnt][r+1] - pref_1[i % 3][cnt][l];
    };

    auto sum_2 = [&](int i, int cnt, int l, int r) {
        if(i < 6) {
            int64_t sum = 0;
            for(int j = l; j <= r; j++) {
                sum = (sum + dp_2[i % 3][cnt][j]) % M;
            }
            return sum;
        }
        else return pref_2[i % 3][cnt][r+1] - pref_2[i % 3][cnt][l];
    };

    for(int i = 2; i < n; i++) {
        for(int j = 0; j < MaxM; j++) {
            for(int k = 0; k < MaxM; k++) {
                dp_0[i%3][j][k] = 0;
                dp_1[i%3][j][k] = 0;
                dp_2[i%3][j][k] = 0;
            }
        }
        for(int cnt = 2; cnt <= i+1; cnt++) {
            for(int k = 1; k <= cnt; k++) {
                dp_0[i % 3][cnt][k] = (
                    sum_0(i-2, cnt-1, 1, cnt-1) +
                    sum_1(i-2, cnt-1, 1, cnt-1) +
                    sum_2(i-2, cnt-1, 1, cnt-1)
                ) % M;
                if(k > 1) {
                    dp_1[i % 3][cnt][k] = (
                        sum_0(i-1, cnt-1, 1, k-1) +
                        sum_1(i-1, cnt-1, 1, k-1) +
                        sum_2(i-1, cnt-1, 1, k-1)
                    ) % M;
                }
                if(k < cnt) {
                    dp_2[i % 3][cnt][k] = (
                        sum_0(i-1, cnt-1, k, cnt-1) +
                        sum_2(i-1, cnt-1, k, cnt-1)
                    ) % M;
                }
            }
        }
        for(int cnt = 2; cnt <= i+1; cnt++) {
            pref_0[i % 3][cnt][0] = 0;
            pref_1[i % 3][cnt][0] = 0;
            pref_2[i % 3][cnt][0] = 0;
            for(int k = 0; k <= cnt; k++) {
                pref_0[i % 3][cnt][k+1] = (pref_0[i % 3][cnt][k] + dp_0[i%3][cnt][k]) % M;
                pref_1[i % 3][cnt][k+1] = (pref_1[i % 3][cnt][k] + dp_1[i%3][cnt][k]) % M;
                pref_2[i % 3][cnt][k+1] = (pref_2[i % 3][cnt][k] + dp_2[i%3][cnt][k]) % M;
            }
        }
    }
    int64_t res = 0;
    for(int j = 0; j < MaxM; j++) {
        for(int k = 0; k < MaxM; k++) {
            res = (res + dp_0[(n-1) % 3][j][k] + dp_1[(n-1) % 3][j][k] + dp_2[(n-1) % 3][j][k]) % M;
        }
    }
    cout << res;

    return 0;
}


