#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 510;
int n, p, fact[N], tot = 1;
int f(int x, int k) {
if (x <= k) return fact[x];
if (k == 1) return 1;
return ((x - 1) * f(x - 1, k) % p + f(x - 1, k - 1) % p) % p;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
freopen("great.in", "r", stdin);
freopen("great.out", "w", stdout);
cin >> n >> p;
for (int i = 1; i <= n; i++) {
tot = tot * i % p;
fact[i] = tot;
}
cout << f(n, 3) % p;
return 0;
}