var a:array[1..2000,1..2000]of qword;
   { b:array[0..2000,0..2000]of string; }
    n,p,i,j:integer;
              {
Function po(k:integer; s:string):string;
var n,o,x,l1,code:integer;
    s1,o1,l:string;
begin n:=0; s1:='';
   repeat
      x:=length(s);
      l:=copy(s,x,1);
      val(l,l1,code);
      o:=(n+k*l1) mod 10;
      n:=(n+k*l1) div 10;
      str(o,o1);
      s1:=o1+s1;
      delete(s,x,1);
   until s='';
      if n<>0 then
        begin str(n,o1);
              s1:=o1+s1;
        end;
      po:=s1;
end;

Function Plus(a,b:string):string;
var n,o,x,y,k1,m1,code:integer;
    s1,o1,k,m:string;
begin n:=0;   s1:='';
   repeat
      x:=length(a);
      y:=length(b);
      k:=copy(a,x,1);
      m:=copy(b,y,1);
      val(k,k1,code);
      val(m,m1,code);
      o:=(n+k1+m1) mod 10;
      n:=(n+k1+m1) div 10;
      str(o,o1);
      s1:=o1+s1;
      delete(a,x,1);
      delete(b,y,1);
   until (a='') and (b='');
      if n<>0 then
        begin str(n,o1);
              s1:=o1+s1;
        end;
      plus:=s1;
end;

Function Modul(s:string):string;
var x,a1,y:longint;
    code:integer;
    a:string;
begin x:=length(s);
      if x<7 then modul:=s
             else
   begin a:=copy(s,1,7);
         delete(s,1,7);
       repeat val(a,a1,code);
              a1:=a1 mod 1020847;
              str(a1,a);
              y:=length(a);
              a:=a+copy(s,1,1);
              delete(s,1,1);
       until s='';
              val(a,a1,code);
              a1:=a1 mod 1020847;
              str(a1,a);
   end;
   modul:=a;
end;
             }




begin readln(n,p);
      a[1,1]:=1;
      for i:=2 to n do
        for j:=1 to i do
           if j=1 then a[i,j]:=(i-1)*a[i-1,j]
                  else
                     if j=i then a[i,j]:=1
                            else a[i,j]:=a[i-1,j-1]+j*a[i-1,j];
      writeln(a[n,p] mod 1020847);
end.
