#include<iostream> using namespace std; int main(){ int n; cin>>n; int a[4],b[4],minn=100001; for(int i=1;i<=3;i++){ cin>>a[i]>>b[i]; int s=0; if(n%a[i]==0)s=n/a[i]*b[i]; else s=(n/a[i]+1)*b[i]; if(s<minn)minn=s; } cout<<minn; return 0; }