import java.util.*

fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    var N = sc.nextInt()
    val M = sc.nextInt()

    val matchMap = mapOf(1 to 2,
                    7 to 3,
                    4 to 4,
                    5 to 5,
                    3 to 5,
                    2 to 5,
                    9 to 6,
                    6 to 6,
                    8 to 7)
    val list = mutableListOf<Pair<Int,Int>>()
    for (n in 0 until M) {
        val A = sc.nextInt()
        if (list.any { it.second==matchMap[A] && it.first>A}) continue
        list.add(A to matchMap[A]!!)
    }
    list.sortBy { it.second}

    fun max (a:String, b:String) :String{
        if (a.length > b.length) return a
        if (a.length < b.length) return b
        if (a > b) return a
        else return b
    }
    val DP = Array(N+1){""}

    for (i in 1 .. N) {
        DP[i] = "0"
        for ((a,n) in list) {
            if (i < n) continue
            if (DP[i-n] == "0") continue
            DP[i] = max(DP[i - n] + "$a", DP[i])
        }
    }
    //DP.forEachIndexed { i, s -> println("$i $s") }

    println(DP[N])
}