#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a1,b1,c1,a2,b2,c2,x=0,y=0,z=0,x1=0,x2=0,x3=0;
cin>>n>>a1>>a2>>b1>>b2>>c1>>c2;
while(x<=n)
{
x+=a1;
x1++;
}
x1*=a2;
while(y<=n)
{
y+=b1;
x2++;
}
x2*=b2;
while(z<=n)
{
z+=c1;
x3++;
}
x3*=c2;
if(x1>=x2>=x3||x1>=x3>=x2)
{
cout<<x1;
}
else if(x2>=x1>=x3||x2>=x3>=x1)
{
cout<<x2;
}
else
{
cout<<x3;
}
return 0;
}