#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
int a[3];
int b[3];
int n;

int main ()
{
  prep();

  cin >> n;

  for (int i=0; i<3; i++){
      cin >> a[i];
  }
  for (int i=0; i<3; i++){
      cin >> b[i];
  }
  bool which[3] = {false};
  int stata = 0;
  for (int i=0; i<3; i++){
      if (b[i]/a[i] >= 1){
          stata++;
          which[i] = true;
      }
  }
  long long maxest = n;
  if (stata == 0 || stata == 3){
      // n choose 2 for other side
      bool sidea = false;
      if (stata == 3){
          sidea = true;
      }
      for (int i=0; i<=n; i++){
          for (int j=i; j<=n; j++){
              
              int one = i;
              int two = j-one;
              int three = n-two-one;
              int places[3] = {one, two, three};
              long long sum = 0;
              if (sidea){
                  for (int k=0; k<3; k++){
                      sum += (places[k]/a[k])*b[k];
                      sum += places[k]%a[k];
                      
                  }
              }else{
                  for (int k=0; k<3; k++){
                      sum += (places[k]/b[k])*a[k];
                      sum += places[k]%b[k];
                      
                  }
              }
              maxest = max(maxest, sum);
          }
      }
  }else if (stata == 1){
      // put all into that one, (new acorn amount) choose 1 for other side
      long long neww = 0;
      for (int i=0; i<3; i++){
          if (which[i]){
              neww += (n/a[i])*b[i];
              neww += n%a[i];
          }
      }
      for (int j=0; j<=neww; j++){
          int one = j;
          int two = neww-one;
          long long res = 0;
          int ind = 0;
          long long places[2] = {one, two};
          for (int k=0; k<3; k++){
              if (!which[k]){
                  res += (places[ind]/b[k])*a[k];
                  res += places[ind]%b[k];
                  ind++;
              }
          }
          maxest = max(maxest, res);
      }
  }else if (stata == 2){
      // n choose 1 for this side, put all into other station's
      long long curmax = 0;
      for (int j=0; j<=n; j++){
          int one = j;
          int two = n-one;
          long long res = 0;
          int ind = 0;
          long long places[2] = {one, two};
          for (int k=0; k<3; k++){
              if (which[k]){
                  res += (places[ind]/a[k])*b[k];
                  res += places[ind]%a[k];
                  ind++;
              }
          }
          
          curmax = max(curmax, res);
      }
    
      for (int i=0; i<3; i++){
          if (!which[i]){
              curmax = curmax%b[i]+(curmax/b[i])*a[i];
              break;
          }
      }
      maxest = max(maxest, curmax);
  }
  cout << maxest;
  return 0; 
}


Measured memory_bytes: 256