#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std::chrono;    

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long 
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
// #define mod 1000000007  
#define mod2 998244353
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)

int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;}
int inverse(int a, int p){return fexp(a, p-2,p);} 

// int fac[2000001];

// int nCrModPFermat(int n, int r,int p) { 
//     // cout<<1<<endl;
//     if (r==0) return 1; 
//     return (((fac[n]*((((inverse(fac[r],p)%p)*inverse(fac[n-r],p))%p))))%p); 
// }
// vi prime(112345,1);
// vi allprime;
// vi spf(10000001,1);
// vi factors[512345];


void solve(){
    int n,mod;cin>>n>>mod;
    vector<int> inversion2(n*n+5,0);
    inversion2[0]=1;
    int ans = 0;
    for(int i=2;i<=n;i++){
        vector<int> sum = inversion2;
        vector<int> prev = inversion2;

        int temp = ans;
        for(int k=n*n-1;k>=0;k--)
            sum[k]=(sum[k]+sum[k+1])%mod;
        for(int j=2;j<=i;j++){
            vector<int> inversion(n*n+5,0);
            for(int k=0;k+j-1<=n*n;k++){
                inversion[k+j-1]=(prev[k]);
            }            
            for(int k=0;k<n*n-1;k++)
                ans=(ans+((inversion[k]*sum[k+1])%mod))%mod;
            
            for(int k=n*n;k>=0;k--){
                inversion2[k]=(inversion2[k]+inversion[k])%mod;
                //sum[k]=(sum[k]+inversion[k]);
            }
            sum = inversion2;
            for(int k=n*n-1;k>=0;k--)
                sum[k]=(sum[k]+sum[k+1])%mod;
            // cout<<ans<<" ";
        }
        ans=(ans+((temp*(i-1))%mod))%mod;
    }
    ans%=mod;
    if(ans<0)ans+=mod;
    cout<<ans;
    
}
         
signed main(){
        IOS;    
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r" , stdin);
        freopen("output.txt", "w", stdout);
        #endif
        auto start = high_resolution_clock::now();
        int t=1; 
        // cin>>t;
        // spf[1]=0;
        // for(int i=2; i<=100005; i++){
        // if(spf[i]==1)
        // {
        //     // allprime.pb(i);
        //     for(int j=i+i; j<=100005; j+=i){
        //         // factors[j].pb(i);
        //         if(spf[j]==1)spf[j]=0;
        //     }
        // }
        //     spf[i]+=spf[i-1];
        // }
        // fac[0] = 1; 
        // for (int i=1 ; i<=200001; i++) fac[i] = fac[i-1]*i%mod; 

        rep(i,0,t){
            // cout<<"Case #"<<i+1<<": ";
            solve();
            cout<<"\n";
        }
        auto stop = high_resolution_clock::now();
        auto duration = duration_cast<microseconds>(stop - start);
        cerr<<"Time taken:"<<duration.count()/1000000.0<<"seconds"<<"\n";
    //    return 0;
}