Program march;
 type masiv=array[1..2000] of integer;
 var k,min,br,i,j,ind,p,n:longint;
     a:masiv;
 Function check(b:masiv):longint;
 var gr,i:longint;
  Begin
   gr:=0; i:=1;
   while i<n do begin
    gr:=gr+1;
    while (b[i]<b[i+1]) and (i<=n) do begin inc(i); b[i]:=b[i-1]; end;
    inc(i);
   end;
   if (i=n) and (a[i]<a[i-1]) then gr:=gr+1;
   check:=gr;

  End;

 Begin
  readln(n,p);
  br:=1;
  if p=n then begin writeln('1'); halt; end;
  if p=1 then begin for i:=2 to n-1 do begin
   br:=(br mod 1020847)*(i mod 1020847);
  end;
   writeln(br mod 1020847); halt; end;
  a[1]:=p;
  for i:=2 to p do a[i]:=i-1;
  for i:=p+1 to n do a[i]:=i;
  br:=0;
  if check(a)=p then br:=br+1;


  repeat
   i:=n-1;
   while (a[i]>a[i+1]) and (i>0) do i:=i-1;
   if i<>0 then begin
    min:=n+1; ind:=0;
    for j:=i+1 to n do if (a[j]<min) and (a[j]>a[i]) then begin min:=a[j]; ind:=j; end;
    min:=a[i]; a[i]:=a[ind]; a[ind]:=min;
    for j:=i+1 to (i+n+1) div 2 do begin
     min:=a[j]; a[j]:=a[n-j+i+1]; a[n-j+i+1]:=min;
    end;
   if check(a)=p then br:=br+1;
   if br>1020847 then br:=br-1020847;
  end;
  until (i=0);


  writeln(br mod 1020847);
 End.
