program bing;
var
f1,f2:text;
s,p:longint;
f,fp:array[0..2500000] 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,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;
end;
begin
init;
nb;
write(f2,f[s]);
close(f1);close(f2);
end.