#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
#include <assert.h>
#include <cstring>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define vec(...) vector<__VA_ARGS__>
#define _3zPnZr8 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;

const int mxn=12000;

int main(){
_3zPnZr8;
	int n,mod;
	cin>>n>>mod;
	const int adup=n*n+3;
	vec(vec(vi)) dp(n,vec(vi)(n*n*2+3,vi(3,0)));
	dp[0][adup][0]=1;
	crep(i,1,n){
		rep(s,n*n*2){
			rep(t,2){	
				if(dp[i-1][s][t]==0) continue;
				rep(x,i+1){
					rep(y,i+1){
						int net=t;
						if(x>y) net=0;
						else if(x<y) net=1;
						dp[i][s+x-y][net]+=dp[i-1][s][t]%mod; dp[i][s+x-y][net]%=mod;
					}
				}
			}
		}
	}
	int ans=0;
	crep(s,adup+1,n*n*2) {ans+=dp[n-1][s][1]%mod; ans%=mod;}
	cout<<ans<<"\n";
// 
	return 0;
}