 {
 formulkata e
 (n-1,p)*p+(n-1,p-1)
 }
 var
 a,b:array [0..2000] of qword;
 n,p,i,j:integer;
 begin
 read(n,p);
 if n=p then writeln(1)
 else
 if n<p then writeln(0)
 else
 begin

 a[1]:=1;
for j:=1 to n-1 do
 begin
  for i:=1 to p do
  b[i]:=(a[i]*i+a[i-1]) mod 1020847;

  b[1]:=a[1]*j mod 1020847;
  a:=b;

 end;

 writeln(a[p]);



 end;



 end.
