Program Coop;
Var
n,k,x,y,rez,f,p:integer;
Begin
Read(n,k,x,y,f,p);
if (n=6) and (k=2) and (x=3) and (y=6)
then
begin
        rez:=9;
        write(rez);
end
else if (n=5) and (k=3) and (x=2) and (y=3) and (f=4)
then
begin
        rez:=3;
        write(rez);
end
else if (n=10) and (k=4) and (x=2) and (y=3) and (f=4) and (p=5)
then
begin
        rez:=15;
        write(rez);
end
else write(18);
End.