R,O=range,print N,P=map(int,input().split()) if N<4:O([1,3,18][N-1]%P),exit() F=[1] G=[1] I=[1] L=R(1,N+1) for i in L: F+=[F[-1]*i%P] I+=[[1,P-P//i*I[P%i]%P][i>1]] G+=[G[-1]*I[i]%P] f=[0] g=[0] for d in L: f+=[pow(d,d-2,P)*G[d]%P] g+=[f[d]*d%P] h=[1]+[0]*N a=0 for d in L: for i in R(N,-1,-1):h[i]=sum(h[j]*g[i-j]for j in R(0,i+1))%P a+=f[d]*h[N] O(a*F[N]%P)