program pohod;
type
 masiv=array[1..2000] of longint;
 var
  n,p:1..2000;
  x:masiv;
  brk,k,j,s:longint;  {brk- broq kombinacii}
BEGIN
 k:=1020847;
 x[1]:=1;
 read(n);readln(p);
 for j:=2 to n do
   begin
     x[j]:= (x[j-1]*j);
     s:=x[j];
     brk:=s div (p+1);end;
     writeln(brk mod (k-208));
     readln;
 end.