program goat;
var
f1,f2:text;
i,t,p,s,pmax:longint;
procedure man;
begin
t:=t+1;
s:=s-1;
p:=p+1;
end;
procedure zhong;
begin
t:=t+1;
s:=s-5;
p:=p-2;
end;
procedure kuai;
begin
t:=t+1;
s:=s-10;
p:=p-5;
end;
{.....................................}
begin
assign(f1,'goat.in');
assign(f2,'goat.out');
reset(f1);rewrite(f2);
readln(f1,s,p);
pmax:=p;
{.....................................}
if p<10 then begin while s>0 do
begin
if p>pmax then p:=pmax;
if p=0 then begin for i:=1 to 10 do begin man;if s<=0 then break;end;end
else begin if p div 5<>0 then kuai
else if p div 2<>0 then zhong
else begin man;if (s>0)and(p<=pmax) then zhong;end;
end;
end;
end
else begin
while s>0 do
begin
if p=0 then man
else begin
if p=10 then begin if s<=20 then begin kuai;if s>0 then kuai;end
else for i:=1 to 5 do zhong;
end
else begin if p div 5<>0 then kuai
else if p div 2<>0 then zhong
else begin man;if s>0 then zhong;end;
end;
end;
end;
end;
writeln(f2,t);
close(f1);close(f2);
end.