var m,n,l,r,i,j,k:longint;
a:array[1..3] of longint;
p,t:array[1..10000000] of longint;
mark:array[1..100000] of boolean;
procedure incpoint(num:longint);
begin
if num>32767
then exit;
inc(r);
p[r]:=num;
t[r]:=t[l]+1;
mark[p[r]]:=true;
if p[r]=m
then begin
writeln(t[r]);
close(input);
close(output);
halt;
end;
end;
begin
assign(input,'wood.in');
reset(input);
assign(output,'wood.out');
rewrite(output);
read(n,m);
for i:=1 to 3 do
read(a[i]);
read(k);
l:=1;r:=1;
p[1]:=n;
mark[n]:=true;
repeat
for i:=1 to 3 do
if not mark[p[l]+a[i]]
then begin
incpoint(p[l]+a[i]);
end;
if p[l]>k
then begin
if not (mark[p[l]-k])
then begin
incpoint(p[l]-k);
end;
if not (mark[k])
then begin
incpoint(k);
end;
end;
if (p[l] div 2 >0)and(not mark[p[l] div 2])
then begin
incpoint(p[l] div 2);
end;
inc(l);
until l>r;
writeln('No solution');
close(input);
close(output);
end.