program march;

const
	MAXN					= 2000;
	M					= 1020847;

type
	Integer					= LongInt;

var
	F					: Array [1 .. MAXN, 1 .. MAXN] of Integer;
	NFact					: Array [1 .. MAXN] of Integer;
	N, P					: Integer;
	i, j					: Integer;

begin
	readln(N, P);
	for i := 1 to N do
		for j := 1 to N do
			F[i, j] := 0;
	NFact[1] := 1;
	for i := 2 to N do
		NFact[i] := (i * NFact[i-1]) mod M;
	F[1, 1] := 1;
	F[2, 1] := 1;
	for i := 3 to N do 
		F[i, 1] := NFact[i-1];
	
	for i := 2 to N do
		for j := 2 to P do begin
			F[i, j] := F[i-1,j-1];
			F[i, j] := (F[i,j] + (((i-1)*F[i-1,j])mod M)) mod M;
		end;
	writeln(F[N, P]);
end.