#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void debug(vec &v) {
	int n = v.size();
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << v[i];
	}
	cout << endl;
}

int n; ll m;
int d;
ll dp[5001][5001];
ll rdp[5002][5002];
ll score[5001][5001];
ll rscore[5002][5002];
void init() {
	d = (n-1) / 2 - 1;
	dp[0][0] = 1;
	dp[1][1] = 1;
	for (int j = 1; j <= 5000; j++) {
		dp[0][j] = dp[0][j - 1];
	}
	for (int j = 2; j <= 5000; j++) {
		dp[1][j] = dp[1][j - 1];
	}
	for (int i = 2; i <= 5000; i++) {
		for (int j = 1; j <= i; j++) {
			dp[i][j] = dp[i - j][j] + dp[i][j - 1];
			if (dp[i][j] >= m)dp[i][j] -= m;
		}
		for (int j = i + 1; j <= 5000; j++) {
			dp[i][j] = dp[i][j - 1];
		}
	}
	for (int i = 0; i <= 5000; i++)for (int j = 0; j <= 5000; j++) {
		score[i][j] = dp[i][j];
		rdp[i+1][j] = rdp[i][j] + dp[i][j];
		if (rdp[i+1][j] >= m)rdp[i+1][j] -= m;
	}
	for (int i = d + 1; i <= n; i++) {
		for (int j = 1; j <= n-1; j++) {
			score[i][j] -= rdp[i - d][j - 1];
			if (n % 2 == 0 && i == n - 1)score[i][j]++;
			if (score[i][j] < 0)score[i][j] += m;
		}
	}
	rep(i, n + 1)rep(j, n + 1) {
		rscore[i+1][j] = rscore[i][j] + score[i][j];
		if (rscore[i+1][j] >= m)rscore[i+1][j] -= m;
	}
}

void solve() {
	cin >> n >> m; mod = m;
	if (n == 2) {
		cout << 3 << endl; return;
	}
	if (n == 4) {
		cout << 16 << endl; return;
	}
	init();
	ll ans = 0;
	//cout << score[5][5] << endl;
	//cout << score[1][1] << " "<<rscore[2][1]<<endl;
	for (int x = 1; x <= n; x++) {
		ll csum = 0;
		int le = x - 1, ri = n - x;
		for (int s = 0; s <= x - 1; s++) {
			(csum += score[s][le] * rscore[x - s][ri])%=mod;
			//cout << score[s][le] <<" "<< rscore[x - s][ri] << endl;
		}
		//cout << x << " ! " << csum << endl;
		ans += csum;
	}
	//cout << ans << endl;
	for (int x = 1; x <= n-1; x++) {
		ll csum = 0;
		int le = x - 1; int ri = n - x - 1;
		int sup = x + x - (x + 1) - d-1;
		if (sup >= 0) {
			for (int s = 0; s <= sup; s++) {
				(csum += score[s][le] * rscore[sup- s+1][ri]) %= mod;
			}
		}
		if (n % 2 == 0)csum = csum * 2 % mod;
		sup++;
		if (sup >= 0) {
			for (int s = 0; s <= sup; s++) {
				(csum += score[s][le] * rscore[sup - s + 1][ri]) %= mod;
			}
		}
		//cout << x << " " << csum << endl;
		ans += csum;
	}
	//cout << ans << endl;
	for (int x = 1; x <= n - 2; x++) {
		ll csum = 0;
		int le = x - 1; int ri = n - x - 2;
		int sup = x + x - (x + 2) - 2*d - 1;
		if (sup >= 0) {
			for (int s = 0; s <= sup; s++) {
				(csum += score[s][le] * rscore[sup - s + 1][ri]) %= mod;
			}
		}
		if (n % 2 == 0)csum = csum * 3 % mod;
		ll ad = 0;
		sup++;
		if (sup >= 0) {
			for (int s = 0; s <= sup; s++) {
				(ad += score[s][le] * rscore[sup - s + 1][ri]) %= mod;
			}
		}
		if (n % 2 == 0)ad = ad * 2 % mod;
		csum = (csum + ad) % mod;
		sup++;
		if (sup >= 0) {
			for (int s = 0; s <= sup; s++) {
				(csum += score[s][le] * rscore[sup - s + 1][ri]) %= mod;
			}
		}
		ans += csum;
	}
	ans %= mod;
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 781952