#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}

ll calc(ll k,P p){
  return (k / p.first)*p.second;
}

ll solve(ll n,vector<P> list){
  //cout << list.size() << endl;
  if(list.size() == 1){
    return calc(n,list[0]) + n % list[0].first;
  }else if(list.size() == 2){
    ll ans = n;
    for(ll i=0; i<=n; i++){
      ll t = n-i;
      ans = max(ans, calc(i,list[0]) + calc(t,list[1]));
    }
    return ans;
  }else{
    ll ans = n;
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n-i; j++){
        int k = n-i-j;
        ans = max(ans, calc(i,list[0]) + calc(j,list[1])+calc(k,list[2]));
      }
    }
    return ans;
  }
}

int main(){
	cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n,t;
  cin >> n;
  vector<int> a,b;
  vector<P> fi,se;
  for(int i=0; i<3; i++){
    cin >> t; 
    a.push_back(t);
  }
  for(int i=0; i<3; i++){
    cin >> t; 
    b.push_back(t);
  }
  for(int i=0; i<3; i++){
    if(a[i]<b[i]){
      P tp(a[i],b[i]);
      fi.push_back(tp);
    }else if(a[i]>b[i]){
      P tp(b[i],a[i]);
      se.push_back(tp);
    }
  }
  //cout << n << endl;
  if(fi.size()>0) n = solve(n,fi);
  if(se.size()>0) n = solve(n,se);
  cout << n << endl;
  return 0;
}
