#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

/*
template<int N = 0> class DynModInt {
private:
	static LL M;
	LL v;
	pair<LL, LL> ext_gcd(LL a, LL b) {
		if(b == 0) { assert(a == 1); return { 1, 0 }; }
		auto p = ext_gcd(b, a % b);
		return { p.SE, p.FI - (a / b) * p.SE };
	}
public:
	DynModInt() { v = 0; }
	DynModInt(LL vv) { assert(M > 0); v = vv; if(abs(v) >= M) { v %= M; } if(v < 0) { v += M; } }
	static void set_M(LL m) { M = m; }
	static LL get_M() { return M; }
	LL get_v() { return v; }
	DynModInt inv() { return ext_gcd(M, v).SE; }
	DynModInt exp(LL b) {
		DynModInt p = 1, a = v; if(b < 0) { a = a.inv(); b = -b; }
		while(b) { if(b & 1) { p *= a; } a *= a; b >>= 1; }
		return p;
	}
	friend bool        operator< (DynModInt   a, DynModInt   b) { return (a.v <  b.v); }
	friend bool        operator> (DynModInt   a, DynModInt   b) { return (a.v >  b.v); }
	friend bool        operator<=(DynModInt   a, DynModInt   b) { return (a.v <= b.v); }
	friend bool        operator>=(DynModInt   a, DynModInt   b) { return (a.v >= b.v); }
	friend bool        operator==(DynModInt   a, DynModInt   b) { return (a.v == b.v); }
	friend bool        operator!=(DynModInt   a, DynModInt   b) { return (a.v != b.v); }
	friend DynModInt   operator+ (DynModInt   a               ) { return DynModInt(+a.v); }
	friend DynModInt   operator- (DynModInt   a               ) { return DynModInt(-a.v); }
	friend DynModInt   operator+ (DynModInt   a, DynModInt   b) { return DynModInt(a.v + b.v); }
	friend DynModInt   operator- (DynModInt   a, DynModInt   b) { return DynModInt(a.v - b.v); }
	friend DynModInt   operator* (DynModInt   a, DynModInt   b) { return DynModInt(a.v * b.v); }
	friend DynModInt   operator/ (DynModInt   a, DynModInt   b) { return a * b.inv(); }
	friend DynModInt   operator^ (DynModInt   a, LL          b) { return a.exp(b); }
	friend DynModInt & operator+=(DynModInt & a, DynModInt   b) { return (a = a + b); }
	friend DynModInt & operator-=(DynModInt & a, DynModInt   b) { return (a = a - b); }
	friend DynModInt & operator*=(DynModInt & a, DynModInt   b) { return (a = a * b); }
	friend DynModInt & operator/=(DynModInt & a, DynModInt   b) { return (a = a / b); }
	friend DynModInt & operator^=(DynModInt & a, LL          b) { return (a = a ^ b); }
	friend istream   & operator>>(istream   & s, DynModInt & b) { s >> b.v; b = DynModInt(b.v); return s; }
	friend ostream   & operator<<(ostream   & s, DynModInt   b) { return (s << b.v); }
};
template<int N> LL DynModInt<N>::M = 0;

// ----
*/
using DMI = LL;//DynModInt<>;

// template<typename T> T MV(T v) { return v; }
// template<typename T, typename ... U> auto MV(T v, int a, U ... b) { return vector<decltype(MV(v, b ...))>(a, MV(v, b ...)); }

const int M = 5000;
LL dp[2][M][M];
int ma[M], next_ma[M + 1];

int main() {
	IN(int, n, m);
	//DMI::set_M(m);
	
	//auto dp = MV<DMI>(0, 2, n, n);
	//vector<int> ma(n);
	inc(i, n) { dp[0][i][n - 1 - i] = 1; ma[i] = n - 1 - i; }
	
	inc(k, n / 2) {
		//if(k % 100 == 0) { OUT(k); }
		
		int kk = (k + 1) & 1;
		inc(s, n) {
		inc(t, ma[s] + 1) {
			dp[kk][s][t] = 0;
		}
		}
		
		//vector<int> next_ma(n);
		
		inc(s, n) {
			if(ma[s] == 0) {
				dp[kk][s][0] = dp[k & 1][s][0];
				continue;
			}
			
			DMI x = 0, y = 0;
			inc(t, ma[s] + 1) {
				x += dp[k & 1][s][t] * (t + 1);
				y += dp[k & 1][s][t];
			}
			x %= m;
			y %= m;
			inc(u, min(s, ma[s]) + 1) {
				//(dp[kk][s - u][u] += x) %= m;
				dp[kk][s - u][u] = (dp[kk][s - u][u] + x) % m;
				next_ma[s - u] = u;
				x -= y;
				y -= dp[k & 1][s][u];
			}
		}
		
		//ma = next_ma;
		dec(s, n - 1) { ma[s] = next_ma[s]; next_ma[s] = 0; }
	}
	
	DMI ans = 0;
	if(n & 1) {
		inc(s, n) {
		inc(t, ma[s] + 1) {
			ans += dp[(n / 2) & 1][s][t];
		}
		}
	} else {
		inc(s, n) { ans += dp[(n / 2) & 1][s][0]; }
	}
	ans %= m;
	if(ans < 0) { ans += m; }
	
	OUT(ans);
}


Measured memory_bytes: 388864