import scala.io.StdIn._
object Main extends App {

  val n = readInt()
  val price = readLine.trim.split(' ').map(_.toInt)
  val t = readLine.trim.split(' ').map(_.toInt)
  val memo = Array.fill(n + 1){Int.MaxValue}.also{_(0) = 0}
  for (i ← 0 until 4) {
    for (j ← memo.indices if memo(j) != Int.MaxValue) {
      val k =  if (j + t(i) > n) n else j + t(i)
      if (memo(k) > memo(j) + price(i)) {
        memo(k) = memo(j) + price(i)
      }
    }
  }
  println(memo.last)

  implicit class Scope[T](val value: T) extends AnyVal {
    def let[A](@inline func: T ⇒ A): A = func(value)
    def also(@inline func: T ⇒ Unit): T = {func(value);value}
  }
}

