uses math;
type bw=record
g,len,nb:longint;
end;
var n,m,i,j,k,l1,l2,l3,l,head,tail:longint; q:array[1..500000]of bw; v:array[0..500000]of boolean;
begin
assign(input,'wood.in'); assign(output,'wood.out'); reset(input); rewrite(output);
readln(n,m); head:=1; tail:=1; q[1].g:=0; q[1].len:=n; readln(l1); readln(l2); readln(l3); read(l);
v[n]:=true; q[1].nb:=n;
while head<=tail do
begin
i:=q[head].len;
if not(v[i+l1]) then
begin inc(tail); q[tail].g:=q[head].g+1; q[tail].len:=i+l1; v[i+l1]:=true;
if q[tail].len=m then begin write(q[tail].g); halt; end; end;
if not(v[i+l2]) then
begin inc(tail); q[tail].g:=q[head].g+1; q[tail].len:=i+l2; v[i+l2]:=true;
if q[tail].len=m then begin write(q[tail].g); halt; end; end;
if not(v[i+l3]) then
begin inc(tail); q[tail].g:=q[head].g+1; q[tail].len:=i+l3; v[i+l3]:=true;
if q[tail].len=m then begin write(q[tail].g); halt; end; end;
if not(v[i>>1]) then
begin inc(tail); q[tail].g:=q[head].g+1; q[tail].len:=i>>1; v[i>>1]:=true;
if q[tail].len=m then begin write(q[tail].g); halt; end; end;
if(q[head].len>l)then
begin
if not(v[l]) then if (q[head].nb>=l) then
begin
inc(tail); q[tail].g:=q[head].g+1; q[tail].len:=l; q[tail].nb:=l; v[l]:=true;
if q[tail].len=m then begin write(q[tail].g); halt; end;
end else
begin
inc(tail); q[tail].g:=q[head].g+1; q[tail].len:=l; q[tail].nb:=q[head].nb; v[l]:=true;
if q[tail].len=m then begin write(q[tail].g); close(input); close(output); halt; end;
end;
if not(v[q[head].len-l]) then
begin
inc(tail); q[tail].g:=q[head].g+1; q[tail].len:=q[head].len-l;
q[tail].nb:=min(q[head].nb,q[head].len-l); v[q[head].len-l]:=true;
if q[tail].len=m then begin write(q[tail].g); halt; end;
end;
end; v[q[head].len]:=false; inc(head); if head>=200000 then begin write('No solution.');
close(input); close(output); halt; end;
end;
end.