#include <bits/stdc++.h>
 
using namespace std;
 
#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;
 
int n;
ll m;
int cd[5010];
ll p[2][5010][5010];
 
ll f(int b, int d) {
  if (d == 0)
    return 1;
  if (b == 0)
    return d + 1;
  while (cd[b] <= min(b, d)) {
    int c = cd[b];
    ll r = f(b - c, c);
    p[0][b][c] = r + (c > 0 ? p[0][b][c - 1] : 0);
    if (p[0][b][c] >= m)
      p[0][b][c] -= m;
    p[1][b][c] = (c * r + (c > 0 ? p[1][b][c - 1] : 0)) % m;
    cd[b]++;
  }
  ll r = (d + 1) * p[0][b][min(b, d)] - p[1][b][min(b, d)];
  return (r % m + m) % m;
}
 
ll g(int b, int d) {
  if (d == 0)
    return b * 2 + (n % 2 == 1);
  if (b == 0)
    return (d + 1) * (n % 2 == 1);
  while (cd[b] <= min(b, d)) {
    int c = cd[b];
    ll r = g(b - c, c);
    p[0][b][c] = r + (c > 0 ? p[0][b][c - 1] : 0);
    if (p[0][b][c] >= m)
      p[0][b][c] -= m;
    p[1][b][c] = (c * r + (c > 0 ? p[1][b][c - 1] : 0)) % m;
    cd[b]++;
  }
  ll r = (d + 1) * p[0][b][min(b, d)] - p[1][b][min(b, d)];
  return (r % m + m) % m;
}
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n >> m;
  ll r = 0;
  for (int s = 1; s <= n; s++)
    r += f(s - 1, n - s);
  for (int i = 0; i < 5010; i++)
    cd[i] = 0;
  for (int s = (n - 1) / 2 + 1; s < n; s++)
    r -= g(s - 1 - (n - 1) / 2, n - s - 1);
  r = (r % m + m) % m;
  cout << r << "\n";
}