# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

nn = inputs[0][0]
as = inputs[1]
bs = inputs[2]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p nn
  p as
  p bs
end

dp1 = [0]
for i in 1..nn do
  cand = [i]
  cand << dp1[i - as[0]] + bs[0] if i >= as[0]
  cand << dp1[i - as[1]] + bs[1] if i >= as[1]
  cand << dp1[i - as[2]] + bs[2] if i >= as[2]
  dp1[i] = cand.max
end

dp2 = [0]
for i in 1..dp1[nn] do
  cand = [i]
  cand << dp2[i - bs[0]] + as[0] if i >= bs[0]
  cand << dp2[i - bs[1]] + as[1] if i >= bs[1]
  cand << dp2[i - bs[2]] + as[2] if i >= bs[2]
  dp2[i] = cand.max
end

puts dp2[-1]
