Program PP1;
Var q:array[1..500000]of longint;
t:array[1..32767]of boolean;
map:array[1..32767]of longint;
l:array[0..3]of longint;
i,j,n,m,k,ss,xx,yy,head,tail:longint;
begin
assign(input,'wood.in'); reset(input);
assign(output,'wood.out'); rewrite(output);
readln(n,m);
for i:=1 to 3 do readln(l[i]);
readln(l[0]);
fillchar(q,sizeof(q),0);
fillchar(t,sizeof(t),false);
for i:=1 to 32767 do map[i]:=10000000;
q[1]:=n; t[n]:=true; map[n]:=0; tail:=1;
if l[0]<>n then begin
q[2]:=l[0]; t[l[0]]:=true; map[l[0]]:=1; inc(tail);
end;
head:=0;
while head<tail do begin
inc(head); xx:=q[head];
if (xx>l[0]) then begin
yy:=xx-l[0];
if (map[yy]>map[xx]+1) then begin
map[yy]:=map[xx]+1;
if t[yy]=false then begin
inc(tail);
q[tail]:=yy;
t[yy]:=true;
end;
end;
end;
yy:=xx div 2;
if (yy<>0)and(map[yy]>map[xx]+1) then begin
map[yy]:=map[xx]+1;
if t[yy]=false then begin
inc(tail);
q[tail]:=yy;
t[yy]:=true;
end;
end;
t[xx]:=false;
end;
for i:=1 to m do
if (map[i]<>10000000) then
for j:=1 to 3 do begin
ss:=i; k:=0;
while ss<m do begin
inc(k);
ss:=ss+l[j];
end;
if (ss=m)and(map[m]>map[i]+1) then map[m]:=map[i]+k;
end;
if map[m]=10000000 then writeln('No solution.') else writeln(map[m]);
close(input);
close(output);
End.