local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max

local n = io.read("*n")
local ga, sa, ba = io.read("*n", "*n", "*n")
local gb, sb, bb = io.read("*n", "*n", "*n")

local dp = {}
for i = 1, n do
  dp[i] = i
end
if ga < gb then
  local max = mfl(n / ga)
  for i = 1, max do
    dp[i * ga] = i * gb
  end
end
if sa < sb then
  for i = n - 1, 1, -1 do
    local addable = mfl((n - i) / sa)
    for j = 1, addable do
      dp[i + j * sa] = mma(dp[i + j * sa], dp[i] + j * sb)
    end
  end
  local max = mfl(n / sa)
  for i = 1, max do
    dp[i * sa] = mma(dp[i * sa], i * sb)
  end
end
if ba < bb then
  for i = n - 1, 1, -1 do
    local addable = mfl((n - i) / ba)
    for j = 1, addable do
      dp[i + j * ba] = mma(dp[i + j * ba], dp[i] + j * bb)
    end
  end
  local max = mfl(n / ba)
  for i = 1, max do
    dp[i * ba] = mma(dp[i * ba], i * bb)
  end
end
local newn = n
for i = 1, n do
  newn = mma(newn, dp[i] + n - i)
end

local changed = n ~= newn
n = newn

local function remchange(xb, xa, yb, ya)
  if xa * yb < ya * xb then
    xb, xa, yb, ya = yb, ya, xb, xa
  end
  local maxmul = mfl(n / xb)
  local maxrem = n % xb
  local maxrem_mul = mfl(maxrem / yb)
  local maxrem_rem = maxrem % yb
  local cand = maxrem_rem + maxrem_mul * ya + maxmul * xa
  -- if maxrem_rem == 0 then print(cand)
  -- else
    for i = maxmul, 0, -1 do
      local base = i * xa
      local rem_mul = mfl((n - base) / yb)
      local rem_rem = (n - base) % yb
      -- if maxrem_rem == rem_rem then break end
      cand = mma(cand, base + rem_mul * ya + rem_rem)
    end
    print(cand)
  -- end
end

-- B to A
if changed then
  if gb < ga then
    if sb < sa then
      remchange(gb, ga, sb, sa)
    elseif bb < ba then
      remchange(gb, ga, bb, ba)
    else
      local rem, mul = n % gb, mfl(n / gb)
      print(rem + mul * ga)
    end
  elseif sb < sa then
    if bb < ba then
      remchange(sb, sa, bb, ba)
    else
      local rem, mul = n % sb, mfl(n / sb)
      print(rem + mul * sa)
    end
  elseif bb < ba then
    local rem, mul = n % bb, mfl(n / bb)
    print(rem + mul * ba)
  else
    print(newn)
  end
else
  for i = 1, n do
    dp[i] = i
  end
  if gb < ga then
    local max = mfl(n / gb)
    for i = 1, max do
      dp[i * gb] = i * ga
    end
  end
  if sb < sa then
    for i = n - 1, 1, -1 do
      local addable = mfl((n - i) / sb)
      for j = 1, addable do
        dp[i + j * sb] = mma(dp[i + j * sb], dp[i] + j * sa)
      end
    end
    local max = mfl(n / sb)
    for i = 1, max do
      dp[i * sb] = mma(dp[i * sb], i * sa)
    end
  end
  if bb < ba then
    for i = n - 1, 1, -1 do
      local addable = mfl((n - i) / bb)
      for j = 1, addable do
        dp[i + j * bb] = mma(dp[i + j * bb], dp[i] + j * ba)
      end
    end
    local max = mfl(n / bb)
    for i = 1, max do
      dp[i * bb] = mma(dp[i * bb], i * ba)
    end
  end
  local newn = n
  for i = 1, n do
    newn = mma(newn, dp[i] + n - i)
  end
  print(newn)
end
