program bing;
var
f1,f2:text;
s,p:longint;
f,fp:array[0..5000000] of longint;
procedure init;
begin
assign(f1,'goat.in');reset(f1);
assign(f2,'goat.out');rewrite(f2);
readln(f1,s,p);
fillchar(f,sizeof(f),0);
fillchar(fp,sizeof(fp),0);
f[0]:=0;fp[0]:=0;
end;
procedure nb;
var
i,j,t,tp:longint;
begin
t:=s;
for i:=1 to s do
begin
if fp[i-1]-1<p then
begin
if f[i-1]+1<t then begin t:=f[i-1]+1;tp:=fp[i-1]-1;
if tp<=0 then tp:=0;end;
end;
if (i-5>=0)and(fp[i-5]+2<=p) then
begin
if f[i-5]+1<t then begin t:=f[i-5]+1;tp:=fp[i-5]+2;end;
end;
if (i-10>=0)and(fp[i-10]+5<=p) then
begin
if f[i-10]+1<t then begin t:=f[i-10]+1;tp:=fp[i-10]+5;end;
end;
f[i]:=t;
fp[i]:=tp;
t:=s;
end;
if s>5 then
for i:=s-1 downto s-5 do
if p-fp[i]>=2 then j:=i;
if s>10 then
for i:=s-5 downto s-10 do
if p-fp[i]>=5 then j:=i;
f[s]:=f[j]+1;
end;
begin
init;
nb;
write(f2,f[s]);
close(f1);close(f2);
end.