fun main(args: Array<String>) {
    val need = intArrayOf(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
    val arr = readLine()!!.split(" ").map { s -> s.toInt() }
    var n = arr[0]
    val a = readLine()!!.split(" ").map { s -> s.toInt() }.sortedBy { need[it]*10 - it }
    var prev =-1
    a.filter { (prev!=need[it]).apply { prev = need[it] } }

    val maxDigArr = arrayOfNulls<Int>(n+1)
    val maxDigArrN = arrayOfNulls<Int>(n+1)
    maxDigArr[0]=0
    fun maxDig(matchc:Int):Int{
        if(matchc<0)return -1
        if( maxDigArr[matchc]==null){
            maxDigArr[matchc]=-1
            a.forEach{ai->
                maxDig(matchc-need[ai]).let {
                    if(it>maxDigArr[matchc]!!){
                        maxDigArr[matchc]=it
                        maxDigArrN[matchc]=ai
                    }else if(maxDigArr[matchc]!=-1&&it==maxDigArr[matchc]!!&&maxDigArrN[matchc]!!<ai){
                        maxDigArrN[matchc]=ai
                    }
                }
            }
            if(maxDigArr[matchc]!=-1)maxDigArr[matchc]=maxDigArr[matchc]!!+1
        }
        return maxDigArr[matchc]!!
    }
    maxDig(n)
    while(n>0) {
        print(maxDigArrN[n]!!)
        n -= need[maxDigArrN[n]!!]
    }
}