N = gets.to_i A = Array.new(3) B = Array.new(3) (0..2).each do |i| A[i], B[i] = gets.split.map(&:to_i) end if A[1]*B[2] < A[2]*B[1] then A[2],B[2],A[1],B[1]=A[1],B[1],A[2],B[2] end if A[0]*B[2] < A[2]*B[0] then A[0],B[0],A[2],B[2]=A[2],B[2],A[0],B[0] end ans=0 (0..A[2]).each do |i| (0..A[2]).each do |j| ans = [ans, (N-A[0]*i-A[1]*j)/A[2]*B[2] + i*B[0]+j*B[1]].max if A[0]*i+A[1]*j <= N end end puts (ans)