program permutation;
var
f:array[0..200,0..200] of longint;
i,j,n,k:longint;
begin
assign(input,'permutation.in');
reset(input);
assign(output,'permutation.out');
rewrite(output);
for i:=1 to 100 do
f[i,0]:=1;
for i:=2 to 100 do
for j:=1 to i-1 do
f[i,j]:=(f[i-1,j]*(j+1)+f[i-1,j-1]*(i-j)) mod 2007;
readln(n,k);
while n>0 do
begin
writeln(f[n,k]);
readln(n,k);
end;
close(input);
close(output);
end.