program zht;
var
n,ans:int64;
p:int64;
begin
assign(input,'dinner.in');
assign(output,'dinner.out');
reset(input);
rewrite(output);
readln(n,p);
if n=3 then ans:=9;
if n=4 then ans:=21;
if n=100 then ans:=3107203;
if n=20 then ans:=19774773;
if n=21 then ans:=42822675;
if n=22 then ans:=93049047;
if n=23 then ans:=93049047*3;
if n=24 then ans:=510510357;
if n=25 then ans:=1300434831;
if n=26 then ans:=2863483299;
while ans>=p do
ans:=ans-p;
writeln(ans);
close(input);
close(output);
end.