program ex;
const
ss:array[1..3]of integer=(1,5,10);
pp:array[1..3]of integer=(-1,2,5);
var
f1,f2:text;
s,p:longint;
mint:longint;
procedure init;
begin
assign(f1,'goat.in');
assign(f2,'goat.out');
reset(f1);
rewrite(f2);
readln(f1,s,p);
close(f1);
mint:=maxint;
end;
procedure pd(t:longint);
begin
if t<mint then mint:=t;
end;
procedure try(t,ns,pt:longint);
var
i:integer;
begin
if t>=mint then exit;
if ns>=s then pd(t)
else begin
if pt>p then pt:=p;
for i:=3 downto 1 do
begin
if pt=0 then try(t+10,ns+10,pt+10);
if pt>pp[i] then try(t+1,ns+ss[i],pt-pp[i]);
end;
end;
end;
begin
init;
try(0,0,p);
writeln(f2,mint);
close(f2);
end.