#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 509
ll n,p,ans[N],num[2][N*N],val[N*N];
ll work(ll m,ll x)
{
	ll res=0;
	for(int i=x+1;i<=(m-1)*(m-2)/2;i++)
		res=(res+val[i-x-1]*num[0][i])%p;
	return res;
}
int main()
{
	scanf("%lld%lld",&n,&p);
	num[1][0]=1;
	for(int k=1;k<=n;k++)
	{
		memset(val,0,sizeof(val));
		val[0]=1;
		for(int i=1;i<=k*(k-1)/2;i++) val[i]=(val[i-1]+num[0][i])%p;
		ans[k]=ans[k-1]*k%p;
		for(int i=1;i<=k;i++) ans[k]=(work(k,i)*(k-i)%p+ans[k])%p;
		for(int i=0;i<=k*(k-1)/2;i++) num[0][i]=num[1][i],num[1][i]=0;
		for(int i=0;i<=k*(k-1)/2;i++)
			for(int j=1;j<=k+1;j++)
				num[1][i+j-1]=(num[1][i+j-1]+num[0][i])%p;
	}
	printf("%lld\n",ans[n]%p);
	return 0;
}