program March;
type AT=array[1..2000] of integer;
var final,comp:Boolean;
    l:longint;
    I,J,n,p,g,max:integer;
    A,A2:AT;
procedure Perm(var B:AT);
var i,p,t,j,c:integer;
    next:Boolean;
begin
 next:=true; c:=n;
 for i:=(n-1) downto 1 do if (B[i]>B[i+1]) then c:=c-1
 else next:=false;
 if c=1 then final:=true
 else if c=n then
 begin
  t:=B[n]; B[n]:=B[n-1]; B[n-1]:=t;
 end
 else
 begin
  p:=c;
   c:=c-1;
  while (B[p]<B[c]) and (p<=n) do p:=p+1;
  for i:=c+1 to n do if (B[i]>B[c]) and (B[i]<B[p]) then p:=i;
  begin
   t:=B[p]; B[p]:=B[c]; B[c]:=t;
  end;
  for i:=c+1 to n-1 do
  for j:=i+1 to n do if B[j]<B[i] then
  begin
   t:=B[j]; B[j]:=B[i]; B[i]:=t;
  end;
 end;
end;
begin
 readln(n,p);
 for I:=1 to n do A[I]:=I;
 for I:=1 to n do A2[I]:=A[I];
 comp:=false;
 while not comp do
 begin
  comp:=true; g:=n;
  for I:=2 to n do if A2[I-1]<A2[I] then
  begin
   A2[I]:=A2[I]-1;
   comp:=false;
   g:=g-1;
  end;
 end;
 if g=p then l:=l+1;
 final:=false;
 while not final do begin
  Perm(A);
  for I:=1 to n do
  begin
   A2[I]:=A[I];
   write(A[I]);
  end;
  comp:=false;
  while not comp do
  begin
   comp:=true; g:=n;
   for I:=2 to n do if A2[I-1]<A2[I] then
   begin
    A2[I]:=A2[I]-1;
    comp:=false;
    g:=g-1;
   end;
   if g=p then l:=l+1;
  end;
 end;
 writeln(l mod 1020847);
end.
