program permutation;
var
n,k,i,j:longint;
f:array[0..100,0..100] of longint;
begin
assign(input,'permutation.in');
assign(output,'permutation.out');
reset(input);
rewrite(output);
for i:=1 to 100 do f[i,0]:=1;
for i:=1 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.