#include <iostream>
using namespace std;

using ll = long long;
int n;
int P;

int dp[2][5050][5050];

inline void update(int& x, int y) {
  x += y;
  if (x >= P) x -= P;
}
int main() {
  cin >> n >> P;
  n--;
  int k = n / 2;
  if (n % 2 == 1)
    dp[0][0][0] = 1;
  else {
    for (int d = 0; d < n + 2; d++)
      if (d * k < n + 2) {
        dp[0][d][d] = 1;
      }
    k--;
  }
  int p = 0;
  for (int i = 0; i < k; i++) {
    for (int j = n + 2 - 1; j >= 0; j--) {
      int cum = 0;
      int s = 0;
      for (int d = 0; d < n + 2; d++) {
        if (d * (k - i) + j < n + 2) {
          update(s, dp[p][d][j]);
          update(cum, s);
          update(dp[p ^ 1][d][d + j], cum);
          dp[p][d][j] = 0;
        } else
          break;
      }
    }
    p ^= 1;
  }
  for (int d = 0; d < n + 2; d++)
    for (int j = 1; j < n + 2; j++) {
      update(dp[p][d][j], dp[p][d][j - 1]);
    }
  ll ans = 0;
  for (int min = 1; min <= n + 1; min++) {
    int md = n + 1 - min;
    for (int d = 0; d <= md; d++) {
      ans += (md - d + 1LL) * dp[p][d][min - 1] % P;
      ans %= P;
    }
  }
  cout << ans << endl;
}
