program march;
var
N,P:integer;
ret: longword;

function fact(h:integer):longword;
var
ret:longword;
a:integer;
begin
  ret:=1;
  for a:=1 to h do
  begin
    ret:=ret*a;
    if (ret>1020874) then
      ret:=ret mod 1020847;
  end;
  fact:=ret;
end;

begin
  readln(N,P);
  ret:=1;
  if (P=1) then
  begin
    ret:=fact(N-1);
    writeln(ret);
  end
  else if(P=N) then
    writeln(1)
  else if (P=N-1) then
  begin
    ret:=(n*p);
    ret:=ret div 2;
    ret:=ret mod 1020847;
    writeln(ret);
  end
  else
  begin
  end;
end.
