#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll INF = 1e15;

ll solve(ll n, ll* a, ll* b) {
  vector<ll> dp(n+1,-INF); dp[0] = 0;
  rep(i,n+1) {
    rep(j,3) {
      if(i-a[j] >= 0) dp[i] = max(dp[i],dp[i-a[j]]+b[j]);
    }
  }
  rep(i,n+1) dp[0] = max(dp[0],dp[i]+n-i);
  return dp[0];
}

int main(){
  ll n;
  cin >> n;
  ll a[3], b[3];
  rep(i,3) cin >> a[i];
  rep(i,3) cin >> b[i];
  cout << solve(solve(n,a,b),b,a) << endl;
  return 0;
}