#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma warning(disable:4996)
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

int dp[5007][5007];
int dp_prev[5007][5007];
int mod;

void calc_dp(int n) {
	dp[0][0] = 1;

	for (int i = 1; i < n/2; ++i) {
		for (int j = 0; j <= n; ++j) {
			int last_border = n;
			if (i+1 != n/2) last_border = n / (n/2 - i - 1);

			for (int k=0; k <= last_border; ++k) {
				dp_prev[j][k] = dp[j][k];
				dp[j][k] = 0;
			}
		}

		for (int j = 0; j <= n; ++j) {
			int last_border = n;
			if (i+1 != n/2) last_border = n / (n/2 - i - 1);

			for (int k=0; k <= last_border; ++k) {
				int new_sum = j + k, new_last = k;
				if (new_sum <= n) {
					dp[new_sum][new_last] += dp_prev[j][k];
					if (dp[new_sum][new_last] >= mod) dp[new_sum][new_last] -= mod;
					//dp[new_sum][new_last] %= mod;
				}
			}
		}

		for (int j = 0; j <= n; ++j) {

			int k = 0;
			while (k <= n) {
				int new_sum = j+1, new_last = k+1;
				if (new_sum > n || (ll) new_sum + (ll) new_last * (n/2 - i - 2) > (ll) n) break;
				dp[new_sum][new_last] += dp[j][k++];
				if (dp[new_sum][new_last] >= mod) dp[new_sum][new_last] -= mod;
			}
		}
	}

	for (int i=0; i <= n; ++i) for (int j=i+1; j < n; ++j) {
		swap(dp[i][j], dp[j][i]);
		swap(dp_prev[i][j], dp_prev[j][i]);
	}



}

int main(){
#ifdef LOCAL
	freopen("L_input.txt", "r", stdin);
	//freopen("L_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n >> mod;

	if (n == 2) {
		cout << 3;
		exit(0);
	}

	calc_dp(n+1);
	

	for (int i=1; i <= n; ++i) {
		for (int j=0; j <= n; ++j) {
			dp[i][j] += dp[i-1][j];
			if (dp[i][j] >= mod) dp[i][j] -= mod;
			dp_prev[i][j] += dp_prev[i-1][j];
			if (dp_prev[i][j] >= mod) dp_prev[i][j] -= mod;
		}
	}

	int ans = 0;

	for (int x = 1; x <= n; ++x) {
		for (int y = x; y <= n; ++y) {
			ll bad = (ll) (n/2 - 1) * (y-x);
			if (bad > (ll) n) continue;
			ll can = (ll) x * ((n+1)/2) - (ll) y * ((n-1)/2);
			if (can <= 0) continue;
			can--;

			//cout << "==== " << x << " " << y << endl;

			int here = 0;

			int A = x-1, B = n - y;
			int tot = 0;
			for (int j = 0; j <= can; ++j) {
				tot = (tot + dp_prev[B][j]);
				if (tot >= mod) tot -= mod;
			}

			//if (x==3 && y==3) cout << can << " " << B << " " << tot << endl;

			for (int take = 0; take <= can; ++take) {
				//if (x==3 && y==3) cout << tot << " " << dp[A][take] << endl;
				int Q = ((ll) tot * dp[A][take]) % mod;
				here += Q;
				if (here >= mod) here -= mod;
				if (take != can) {
					tot = (tot - dp_prev[B][can-take] + mod);
					if (tot >= mod) tot -= mod;
				}
			} 
			if (n%2 == 0) {
				here = ((ll) here * (y-x+1)) % mod;
			}

			//cout << "==== " << x << " " << y << " " << here << endl;

			ans = (ans + here) % mod;
		}
	}

	cout << ans;



}


Measured memory_bytes: 195968