program equationz;
var
i,k,x:longint;
num,g:int64;
procedure init;
begin
assign(input,'equationz.in');
reset(input);
assign(output,'equationz.out');
rewrite(output);
read(k,x);
g:=1; num:=1;
for i:=1 to x do
begin
g:=g*x;
g:=g mod 1000
end;
dec(g);
dec(k)
end;
procedure main;
begin
for i:=g downto (g-k+1) do
num:=num*i;
for i:=1 to k do
num:=num div i
end;
procedure print;
begin
writeln(num);
close(input);
close(output)
end;
begin
init;
main;
print
end.