var
a,used,b:array[1..20] of integer;
g:array[1..2000] of int64;
n,i,p:integer;
f:int64;
function fact(x:integer):int64;
var q:int64;
y:integer;
begin
q:=1;
for y:=1 to x do
 q:=q*y;
fact:=q;
end;
procedure gen(x:integer);
var k,j,br:integer;
begin
 if i=n then begin
             for j:=1 to n do
             b[j]:=a[j];
             br:=0;
             for j:=n downto 2 do
              if b[j]<b[j-1] then begin b[j-1]:=b[j]; inc(br); end;
             g[n-br]:=g[n-br]+1;
             end
        else for k:=1 to n do
              if used[k]=0 then begin
               used[k]:=1;
               a[i+1]:=k; inc(i);
               gen(k);
               used[k]:=0; dec(i);
              end;
end;
begin
readln(n,p);
if p=n then writeln(1)
       else if p=1 then begin f:=fact(n-1); f:=f mod 1020847; writeln(f) end
                   else begin
                         i:=0;
                         gen(1);
                         writeln(g[p]);
                        end;
end.
