#include <stdio.h>

#define N	500
#define M	(N * (N - 1) / 2)

int dr[M + 1], ds[M + 1], md;

int sum(int l, int r) {
	return (dr[r] - (l <= 0 ? 0 : dr[l - 1])) % md;
}

int sum_(int l, int r) {
	return (ds[r] - (l <= 0 ? 0 : ds[l - 1] + (long long) dr[l - 1] * (r - l + 1))) % md;
}

int main() {
	static int dp[M + 1], dq[M + 1];
	int n, k, h, i, ans;

	scanf("%d%d", &n, &md);
	ans = 0, dp[0] = 1;
	for (k = 1; k <= n; k++) {
		int m = (k - 1) * (k - 2) / 2, x;

		for (h = 0; h <= m; h++)
			dq[h] = ((h == 0 ? 0 : dq[h - 1]) + dp[h]) % md;
		for (h = 0; h <= m; h++)
			dr[h] = ((h == 0 ? 0 : dr[h - 1]) + dq[h]) % md;
		for (h = 0; h <= m; h++)
			ds[h] = ((h == 0 ? 0 : ds[h - 1]) + dr[h]) % md;
		x = 0;
		for (h = 2; h <= m; h++)
			x = (x + ((long long) sum(h - k, h - 2) * k - sum_(h - k, h - 2)) % md * dp[h]) % md;
		for (i = 0; i < n - k; i++)
			x = (long long) x * (n - i) % md;
		ans = (ans + x) % md;
		for (h = 1; h <= m + k - 1; h++)
			dp[h] = (dp[h] + dp[h - 1]) % md;
		for (h = m + k - 1; h >= k; h--)
			dp[h] = (dp[h] - dp[h - k]) % md;
	}
	if (ans < 0)
		ans += md;
	printf("%d\n", ans);
	return 0;
}
