import scala.io.StdIn

object Main {

  def main(args: Array[String]) = {

    val n = StdIn.readLine().toInt
    val ratea = StdIn.readLine().split(' ').map(_.toInt).toVector
    val rateb = StdIn.readLine().split(' ').map(_.toInt).toVector

    val maxInStep3 = f(n, ratea, rateb)
    val maxInStep4 = f(maxInStep3, rateb, ratea)
    println(maxInStep4)
  }

  def f(n: Int, before: Vector[Int], after: Vector[Int]): Int = {

    val diffs = (0 until 3).map(i => (i, after(i) - before(i), before(i), after(i)))
    val value = diffs.sortBy(_._2 * -1)
    val deal  = value.foldLeft((0, n))((acc, v) =>
      if (v._2 > 0) {
        (acc._1 + acc._2 / v._3 * v._4, acc._2 % v._3)
      } else {
        acc
      }
    )
    deal._1 + deal._2
  }


}
