#include <bits/stdc++.h>
using namespace std;
int n;
struct T
{
int v,w;
double x;
}a[1005];
bool cmp(T x,T y)
{
return x.x > y.x;
}
int main()
{
cin >> n;
for (int i = 1;i <= 3;i++)
{
cin >> a[i].v >> a[i].w;
a[i].x = a[i].w / a[i].v / 1.0;
}
sort(a + 1,a + n + 1,cmp);
long long sum = 0,cnt = 0;
while (sum >= n)
{
sum += a[1];
cnt++;
}
cout << a[1].w * cnt;
}