jj=10000;
type
tt=array[0..31]of longint;
var
f:array[0..1023]of tt;
zero,t:tt;
n,a,b,c,d,i,j:longint;
operator +(x:tt;y:longint)z:tt;
var
i:longint;
begin
z:=x;
inc(z[1],y);
for i:=1 to z[0]-1 do
if z[i]>=jj then
begin
dec(z[i],jj);
inc(z[i+1]);
end;
if z[z[0]]>=jj then
begin
dec(z[z[0]],jj);
inc(z[0]);
z[z[0]]:=1;
end;
end;
operator *(x:tt;y:longint)z:tt;
var
i:longint;
begin
fillchar(z,sizeof(z),0);
z[0]:=x[0];
for i:=1 to x[0] do
z[i]:=x[i]*y;
for i:=1 to z[0]-1 do
begin
inc(z[i+1],z[i] div jj);
z[i]:=z[i] mod jj;
end;
if z[z[0]]>=jj then
begin
z[z[0]+1]:=z[z[0]] div jj;
z[z[0]]:=z[z[0]] mod jj;
inc(z[0]);
end;
end;
operator >(x,y:tt)z:boolean;
var
i:longint;
begin
if x[0]>y[0] then exit(true) else
if x[0]<y[0] then exit(false) else
for i:=x[0] downto 1 do
if x[i]>y[i] then exit(true) else
if x[i]<y[i] then exit(false);
exit(false);
end;
begin
zero[0]:=1;zero[1]:=0;
readln(n,a,b,c,d);
b:=b+c;
f[0]:=zero;
for i:=1 to n do
begin
if i>=a then f[i]:=f[i-a]+1 else f[i]:=zero;
for j:=2 to (i-b) div d do
begin
t:=f[i-b-j*d]*j;
if t>f[i] then f[i]:=t;
end;
end;
write(f[n,f[n,0]]);
for i:=f[n,0]-1 downto 1 do
write(f[n,i]div 1000,f[n,i]div 100 mod 10,f[n,i]div 10 mod 10,f[n,i]mod 10);
writeln;
end.