fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val A = listOfInt().sortedDescending()
    val U = arrayListOf(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
    val V = A.map { U[it] }
    val dp = Array<String?>(10001) { null }; dp[0] = ""
    for (n in 1 .. N) {
        for (m in 0 until M) {
            val t = n - V[m]
            if (t >= 0 && dp[t] != null) {
                if (dp[n] == null) dp[n] = ""
                if (dp[n]!!.length <= dp[t]!!.length) {
                    dp[n] = dp[t] + A[m]
                }
            }
        }
    }
    val ans = dp[N]!!.split("").sortedDescending()
    println(ans.joinToString(""))
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)