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])
end

n = newn

-- B to A
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])
end
print(newn)
