program goat;
const
ss:array[1..3]of integer=(1,5,10);
pp:array[1..3]of integer=(-1,2,5);
var
ans,s,p:longint;
procedure init;
begin
assign(input,'goat.in');
reset(input);
assign(output,'goat.out');
rewrite(output);
readln(s,p);
ans:=maxlongint;
close(input);
end;
procedure try(t,s1,p1:longint);
var
i:longint;
begin
if t>=ans then exit;
if s1>=s then begin if t<=ans then ans:=t end
else begin
if p1>p then p1:=p;
for i:=3 downto 1 do
begin
if p1=0 then try(t+10,s1+10,p1+10);
if p1>pp[i] then try(t+1,s1+ss[i],p1-pp[i]);
end;
end;
end;
begin
init;
try(0,0,p);
writeln(ans);
close(output);
end.