#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

long long mod_pow(long long a,long long b,long long MOD)
{
    a %= MOD;
    long long res = 1;
    while(b){
        if(b & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}


ll a[5010][5010];
ll b[5010][5010];

int main(){
    ll n,mod;
    cin >> n >> mod;
    if(n%2==0){
        int k = n/2 ;
        a[0][0] = 1;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                if(j!=0){
                    a[i][j] += a[i][j-1];
                    if(a[i][j]>=mod)a[i][j]-=mod;
                    // a[i][j] %= mod;
                }
                if(i>=j){
                    a[i][j] += a[i-j][j];
                    if(a[i][j]>=mod)a[i][j]-=mod;
                    // a[i][j] %= mod;
                }
                if(j!=0&&i-j-k>=0){
                    a[i][j] += mod - a[i-j-k][j-1];
                    if(a[i][j]>=mod)a[i][j]-=mod;
                    // a[i][j] %= mod;
                }
            }
        } 
        b[0][0] = 1;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                if(j!=0){
                    b[i][j] += b[i][j-1];
                    if(b[i][j]>=mod)b[i][j]-=mod;
                    //b[i][j] %= mod;
                }
                if(i>=j){
                    b[i][j] += b[i-j][j];
                    if(b[i][j]>=mod)b[i][j]-=mod;
                    //b[i][j] %= mod;
                }
                if(j!=0&&i-j-k+1>=0){
                    b[i][j] += mod - b[i-j-k+1][j-1];
                    if(b[i][j]>=mod)b[i][j]-=mod;
                    //b[i][j] %= mod;
                }
            }
        } 
        rep(i,n+1){
            rep(j,n+1){
                if(i!=0){
                    b[i][j] += b[i-1][j];
                    if(b[i][j]>=mod)b[i][j]-=mod;
                    //b[i][j] %= mod;
                }
            }
        }
        ll ans = 0;
        for(int x = 1;x<=n;x++){
            for(int y=0;y<=x-1;y++){
                ans += (a[y][x-1]*b[x-1-y][n-x])%mod;
                ans %= mod;
            }
        }
        cout << ans*mod_pow(4,mod-2,mod)%mod << endl;
    }else{
        int k = n/2 ;
        a[0][0] = 1;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                if(j!=0){
                    a[i][j] += a[i][j-1];
                    if(a[i][j]>=mod)a[i][j]-=mod;
                    // a[i][j] %= mod;
                }
                if(i>=j){
                    a[i][j] += a[i-j][j];
                    if(a[i][j]>=mod)a[i][j]-=mod;
                    // a[i][j] %= mod;
                }
                if(j!=0&&i-j-k>=0){
                    a[i][j] += mod - a[i-j-k][j-1];
                    if(a[i][j]>=mod)a[i][j]-=mod;
                    // a[i][j] %= mod;
                }
            }
        } 
        b[0][0] = 1;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                if(j!=0){
                    b[i][j] += b[i][j-1];
                    if(b[i][j]>=mod)b[i][j]-=mod;
                    //b[i][j] %= mod;
                }
                if(i>=j){
                    b[i][j] += b[i-j][j];
                    if(b[i][j]>=mod)b[i][j]-=mod;
                    //b[i][j] %= mod;
                }
                if(j!=0&&i-j-k>=0){
                    b[i][j] += mod - b[i-j-k][j-1];
                    if(b[i][j]>=mod)b[i][j]-=mod;
                    //b[i][j] %= mod;
                }
            }
        } 
        rep(i,n+1){
            rep(j,n+1){
                if(i!=0){
                    b[i][j] += b[i-1][j];
                    if(b[i][j]>=mod)b[i][j]-=mod;
                    //b[i][j] %= mod;
                }
            }
        }
        ll ans = 0;
        for(int x = 1;x<=n;x++){
            for(int y=0;y<=x-1;y++){
                ans += (a[y][x-1]*b[x-1-y][n-x])%mod;
                ans %= mod;
            }
        }
        cout << ans*mod_pow(4,mod-2,mod)%mod << endl;
    }
    return 0;
}

Measured memory_bytes: 392064