program soitario;
uses Math;
var N,M,i,j, soluzione, con_x, senza_x, nuovariga, nuovacolonna:longint;
griglia:array[0..12,0..12] of longint;
function gioca(r, c: longint): boolean;
begin
(*tris orizzontale*)
if (c-2>=0) and (griglia[r][c-2]=1) and (griglia[r][c-1]=1) then gioca:=false
(*tris orizzontale*)
else if (r-2>=0) and (griglia[r-2][c]=1) and (griglia[r-1][c]=1) then gioca:=false
(* Tris diagonale in alto a sx*)
else if (r-2>=0 ) and (c-2>=0) and (griglia[r-2][c-2]=1) and (griglia[r-1][c-1]=1) then gioca:=false
(* Tris diagonale in alto a dx*)
else if (r-2>=0) and (c+2<=M) and (griglia[r-2][c+2]=1) and (griglia[r-1][c+1]=1) then gioca:=false
else gioca := true;
end;
function riempi (riga, colonna:longint):longint;
begin
if griglia[riga,colonna]=-1 then
begin
if colonna+1=M then begin if riga<N-1 then nuovariga:=riga+1
else exit; end
else nuovariga:=riga;
if colonna<N then nuovacolonna:= (colonna+1) mod M;
(*Se posso, metto la X*)
if gioca (riga,colonna)=true then
begin
griglia[riga,colonna]:=1;
con_x:= 1 + Riempi(nuovariga,nuovacolonna);
(* Reset della griglia[riga][col]*)
end;
(* Non metto la X*)
griglia[riga][colonna]:=0;
senza_x:= Riempi(nuovariga,nuovacolonna);
(*Ritorno la soluzione migliore*)
griglia[riga,colonna]:=max(con_x, senza_x);
riempi:=griglia[riga,colonna]
end;
riempi:=griglia[riga,colonna] ;
end;
begin
readln(N,M);
for i:=0 to N do
for j:=0 to M do griglia[i,j]:=-1;
writeln(riempi(0 ,0));
end.
cHJvZ3JhbSBzb2l0YXJpbzsKdXNlcyBNYXRoOwp2YXIgTixNLGksaiwgc29sdXppb25lLCBjb25feCwgc2VuemFfeCwgbnVvdmFyaWdhLCBudW92YWNvbG9ubmE6bG9uZ2ludDsKICAgIGdyaWdsaWE6YXJyYXlbMC4uMTIsMC4uMTJdIG9mIGxvbmdpbnQ7CiAgICAKZnVuY3Rpb24gZ2lvY2EociwgYzogbG9uZ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ErMQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbHNlIGV4aXQ7IGVuZAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSBudW92YXJpZ2E6PXJpZ2E7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiBjb2xvbm5hPE4gdGhlbiBudW92YWNvbG9ubmE6PSAoY29sb25uYSsxKSBtb2QgTTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICgqU2UgcG9zc28sIG1ldHRvIGxhIFgqKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgZ2lvY2EgKHJpZ2EsY29sb25uYSk9dHJ1ZSB0aGVuCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJlZ2luIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JpZ2xpYVtyaWdhLGNvbG9ubmFdOj0xOyAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uX3g6PSAxICsgUmllbXBpKG51b3ZhcmlnYSxudW92YWNvbG9ubmEpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKCogUmVzZXQgZGVsbGEgZ3JpZ2xpYVtyaWdhXVtjb2xdKikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICgqIE5vbiBtZXR0byBsYSBYKikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdyaWdsaWFbcmlnYV1bY29sb25uYV06PTA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZW56YV94Oj0gUmllbXBpKG51b3ZhcmlnYSxudW92YWNvbG9ubmEpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKCpSaXRvcm5vIGxhIHNvbHV6aW9uZSBtaWdsaW9yZSopCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdyaWdsaWFbcmlnYSxjb2xvbm5hXTo9bWF4KGNvbl94LCBzZW56YV94KTsgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJpZW1waTo9Z3JpZ2xpYVtyaWdhLGNvbG9ubmFdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsKICAgICAgICByaWVtcGk6PWdyaWdsaWFbcmlnYSxjb2xvbm5hXSA7CiAgICAgICAgCmVuZDsgICAgICAgICAgICAgICAgICAgCmJlZ2luCglyZWFkbG4oTixNKTsKCWZvciBpOj0wIHRvIE4gZG8KCSAgICAgICAgICAgIGZvciBqOj0wIHRvIE0gZG8gZ3JpZ2xpYVtpLGpdOj0tMTsKCXdyaXRlbG4ocmllbXBpKDAgLDApKTsKZW5kLgo=