import java.math.*

val map = mapOf(1 to 2, 2 to 5, 3 to 5, 4 to 4, 5 to 5, 6 to 6, 7 to 3, 8 to 7, 9 to 6)

fun main(args: Array<String>) {
    val (n, m) = readInputLine().split(" ").map{it.toInt()}
    val aList = readInputLine().split(" ").map{it.toInt()}.sortedDescending()
    
    val dp = IntArray(n + 1, {Int.MIN_VALUE})
    dp[0] = 0
    
    for (i in 1..n) {
        for (a in aList) {
            val oldIndex = i - map.get(a)!!
            if (oldIndex < 0) {
                continue
            }
            dp[i] = Math.max(dp[i], dp[oldIndex] + 1)
        }
    }
    
    var remain = n
    
    while (remain != 0) {
        for (a in aList) {
            val match = map.get(a)!!
            if (remain - match < 0) {
                continue
            }
            if (dp[remain - match] == dp[remain] - 1) {
                print(a)
                remain -= match
                break
            }
        }
    }
    
    println()
}

fun readInputLine(): String {
    return readLine()!!
}

