program ex;
type
ss=array[1..1200]of integer;
var
a:ss;
n,p:integer;
f1,f2:text;
max,t:longint;
procedure init;
begin
assign(f1,'subway.in');
assign(f2,'subway.out');
reset(f1);
rewrite(f2);
readln(f1,n,p);
close(f1);
end;
procedure main;
var
i:integer;
begin
for i:=1 to n-1 do
max:=(max*i)mod 4096;
max:=(max*p-n*(n-1-p))mod 4096;
writeln(f2,max);
end;
begin
init;
if p=1 then writeln(f2,'1')
else main;
close(f2);
end.