{[CT]}
const
   max = 1020847;
var
  a,b:array[0..2000] of cardinal;
  c,d:pointer;
  n,p,i,j:word;
begin
  read(n,p);
  if (n=1)or(n=p) then
  begin
     writeln(1);
     exit;
  end;
  a[1]:=1;
  for i:=2 to p do
  begin
    for j:=1 to i do
      b[j]:=((i-1)*a[j]+a[j-1]) mod max;
     a:=b;
  end;
  for i:=p+1 to n do
  begin
    for j:=1 to p do
      b[j]:=((i-1)*a[j]+a[j-1]) mod max;
     a:=b;
  end;
  writeln(b[p] mod max);
end.