import java.lang.StringBuilder

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val A = readLine()!!.split(" ").map{it.toInt()}.sorted()

    val matches = arrayOf(100, 2, 5, 5, 4, 5, 6, 3, 7, 6)
    val dp = Array(M + 1) { Array(N + 1) {-1}  }
    val prev = Array(M + 1) { Array(N + 1) {Pair(-1, -1)}  }

    dp[0][0] = 0

    for (i in A.indices) {
        for (k in dp[i].indices) {
            dp[i + 1][k] = dp[i][k]
            prev[i + 1][k] = Pair(i, k)

            if (k >= matches[A[i]] && dp[i + 1][k] <= dp[i + 1][k - matches[A[i]]] + 1) {
                dp[i + 1][k] = dp[i + 1][k - matches[A[i]]] + 1
                prev[i + 1][k] = Pair(i + 1, k - matches[A[i]])
            }
        }
    }

    val res = StringBuilder()
    var p = Pair(A.size, N)

    while (p.first > 0) {
        val q = prev[p.first][p.second]
        if (p.first == q.first) {
            res.append(A[p.first - 1])
        }
        p = q
    }

    println(res.toString())
}
