fun main(arr:Array<String>) {
    val n = readLine()!!.toLong()

    val tran = (1..5).map { readLine()!!.toLong() }

    val timeTable = mutableListOf(State(0, n/tran[0] - 1 + if (n % tran[0] == 0L) 0 else 1))
    for(i in (1 until tran.count())) {
        val startTime = timeTable.last().startTime + 1
        var endTime = timeTable.last().endTime + 1
        if(tran[i] < tran[i-1]) {
            val diff = n / tran[i] + if(n%tran[i] == 0L) 0 else 1
            endTime = Math.max(startTime + diff  - 1, endTime)
        }
        timeTable.add(State(startTime, endTime))
    }
    println(timeTable.last().endTime + 1)
}

class State(val startTime:Long, val endTime:Long)
