def main(argv)
  n = gets.chomp.to_i
  (g_a, s_a, b_a) = gets.chomp.split(' ').map(&:to_i)
  (g_b, s_b, b_b) = gets.chomp.split(' ').map(&:to_i)
  
  k_a = [g_a, s_a, b_a].max
  dp_a = [0] * (n + 1)
  n.times do |i|
    dp_a[i + g_a] = [dp_a[i + g_a], dp_a[i] + (g_b - g_a)].max if i + g_a <= n
    dp_a[i + s_a] = [dp_a[i + s_a], dp_a[i] + (s_b - s_a)].max if i + s_a <= n
    dp_a[i + b_a] = [dp_a[i + b_a], dp_a[i] + (b_b - b_a)].max if i + b_a <= n
  end
  
  m = n + dp_a.max
  k_b = [g_b, s_b, b_b].max
  dp_b = [0] * (m + 1)
  m.times do |i|
    dp_b[i + g_b] = [dp_b[i + g_b], dp_b[i] + (g_a - g_b)].max if i + g_b <= m
    dp_b[i + s_b] = [dp_b[i + s_b], dp_b[i] + (s_a - s_b)].max if i + s_b <= m
    dp_b[i + b_b] = [dp_b[i + b_b], dp_b[i] + (b_a - b_b)].max if i + b_b <= m
  end
  
  puts (m + dp_b.max).to_s
end

if self.to_s == 'main' then
  main(ARGV)
end