#include <cstdio>
 
/*
max(N- [x2, ..., xN] [ 1 2 3 4 ... 4 3 2], 0)
 
(1 + z + z^2 + ... + z^N) (1 + z^2 + z^4 + ... + z^{2N}) ...
f(z) = 1/[(1-z){(1-z^2)(1-z^3)...(1-z^{N/2})}^2]
 
 
[z^N] (N f(z) - z * f'(z))/(1-z)
[z^N] (f(z)(N - z * f'(z)/f(z)))/(1-z)
 
f'(z)/f(z) = 1/(1-z) + 2(2z/(1-z^2) + 3z^2/(1-z^3) + ...
 
log f = \sum_{i=2}^{N/2}
 
f(z) = (1-z)(1-z^{N/2+1})^2(1-z^{N/2+2})^2... / [(1-z)(1-z^2)...]^2
f(z) = (1-z)(1-2z^{N/2+1})(1-2z^{N/2+2})... / [(1-z)(1-z^2)...]^2
f(z) = (1-z)(1-2z^{N/2+1}-2z^{N/2+2}-...) / [(1-z)(1-z^2)...]^2
f(z) = (1-z-2z^{N/2+1}) / [(1-z)(1-z^2)...]^2

[z^N] (Nz^N + (N-1)z^{N-1} + .. z + 0) f(z)
[z^{N-1}] (Nz^{N-1} + (N-1)z^{N-2} + .. 2z + 1) f(z)
[z^{N-1}] 1/(1-z)^2 f(z)
 
f(z) = 1/[(1-z)(1-z^2)(1-z^3)...(1-z^{N/2})]^2
f(z) = (1-2z^{N/2+1} - ... )/[(1-z)(1-z^2)...]^2
f(z) = (1-z-2z^{N/2+1})/{(1-z)[(1-z)(1-z^2)...]^2}
*/

 
int n, m;
 
int dp[5000];

int main(){
  scanf("%d%d", &n, &m);

  for(int i = 0; i <= n/2; i++) dp[i] = 1;
  for(int i = (n+1)/2+1, j = 0; i < n; i++, j++) dp[i] = m - (1+2*j);
  
  for(int t = 0; t < 2; t++){ 
    for(int i = 0; i < n; i++){
      long long int tmp = dp[i];
      for(int j = 1; ; j++){
        int k = j * (3 * j - 1) / 2;
        if(k > i) break;
        if(j&1){
          tmp += dp[i - k];
        }
        else {
          tmp -= dp[i - k];
        }
        k += j;
        if(k > i) break;
        if(j&1){
          tmp += dp[i - k];
        }
        else {
          tmp -= dp[i - k];
        }
      }
      dp[i] = tmp % m;
    }
  }

  if(n & 1){
    if(dp[n-1] < 0) dp[n-1] += m;
    if(dp[n-1-(n+1)/2-1] < 0) dp[n-1-(n+1)/2-1] += m;
    dp[n-1] -= dp[n-1-(n+1)/2-1];
    if(dp[n-1] < 0) dp[n-1] += m;
  }

  if(dp[n-1] < 0) dp[n-1] += m;
 
  printf("%d\n", (int) dp[n-1]);
 
 
  return 0;
}
