var
n,m,i,j:longint;
f:array[0..1000,0..1000]of longint;
function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end;
begin
assign(input,'permutation.in'); reset(input);
assign(output,'permutation.out'); rewrite(output);
n:=1000;
m:=1000;
for i:=1 to n do
for j:=0 to m do
begin
f[i,j]:=0;
if j=0 then f[i,j]:=1;
end;
for i:=2 to n do
for j:=1 to min(i-1,m) do
begin
if j=i-1 then f[i,j]:=1
else f[i,j]:=(f[i-1,j-1]*(i-j)+f[i-1,j]*(j+1)) mod 2007;
end;
repeat
readln(n,m);
writeln(f[n,m]);
until eof;
close(input);
close(output);
end.