var n,m:longint;
ans:array[0..32767] of longint;
f:array[1..4000000] of longint;
v:array[0..32767] of boolean;
head,tail,now:longint;
a:array[0..4] of longint;
i,j,ans1,t:longint;
begin
assign(input,'wood.in'); reset(input);
assign(output,'wood.out'); rewrite(output);
readln(n,m);
for i:=1 to 4 do
readln(a[i]); ans1:=0;
fillchar(v,sizeof(v),false);
fillchar(ans,sizeof(ans),0);
head:=0; tail:=1; f[1]:=0; v[0]:=true;
while ((head<>tail) and (ans1<40000000)) do
begin
head:=(head mod 4000000)+1; now:=f[head];
for i:=1 to 3 do
begin
t:=now+a[i]; if t=m then begin writeln(ans[now]+1); halt; end;
if not v[t] then begin tail:=(tail mod 4000000)+1; f[tail]:=t; ans[t]:=ans[now]+1; v[t]:=true; end;
end;
for i:=1 to 3 do
begin
t:=now+(a[i] div 2); if t=m then begin writeln(ans[now]+1); halt; end;
if not v[t] then begin tail:=(tail mod 4000000)+1; f[tail]:=t; ans[t]:=ans[now]+1; v[t]:=true; end;
end;
if n>=a[4] then begin n:=n-a[4]; t:=now+a[4];
if t=m then begin writeln(ans[now]+1); halt; end;
if not v[t] then begin tail:=(tail mod 4000000)+1; f[tail]:=t; ans[t]:=ans[now]+1; v[t]:=true; end;
end;
inc(ans1);
end;
writeln('No solution.');
close(output);
end.