/*
failed
debugging is painful
but i don't know why
perhaps, i need a more detailed solution (?)
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
// #define Debug
// #define LOCAL
const int N = 800;
int n;
long long P;
long long inv[N + 5];
void init_inv()
{
inv[1] = 1;
for (int i = 2; i <= n; i++)
inv[i] = (P - P / i) * inv[P % i] % P;
return ;
}
long long f[N + 5][N + 5], g[N + 5];
void addto(long long &x, long long y)
{
x = (x + y) % P;
return ;
}
int main()
{
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("mycode.out", "w", stdout);
#endif
scanf("%d%lld", &n, &P);
init_inv();
f[1][0] = 1, g[1] = 1;
for (int i = 2; i <= n; i++)
{
g[i] = f[i - 1][0] * inv[i] % P;
for (int j = 0; j <= i; j++)
{
addto(f[i][j], f[i - 1][j + 1] * inv[i] % P);
for (int k = 1; k <= i; k++)
{
addto(f[i][j], f[i - k][j] * g[k] % P * k % P * inv[i] % P);
if (j > 0)
addto(f[i][j], f[i - k][j - 1] * g[k] % P * (P - k) % P * inv[i] % P);
}
}
#ifdef Debug
cout << i << " legal = ";
long long res = g[i];
for (int t = 1; t <= i; t++)
res = res * t % P;
cout << res << endl;
#endif
}
long long ans = g[n];1
for (int i = 1; i <= n; i++)
ans = ans * i % P;
printf("%lld\n", ans);
return 0;
}