fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }.sorted()
    val match = intArrayOf(0,2,5,5,4,5,6,3,7,6)

    val dp = IntArray(n+10){-1}
    dp[0] = 0
    repeat(n) { i ->
        a.forEach { dp[i+match[it]] = Math.max(dp[i+match[it]], dp[i] + 1 ) }
    }

    var ans = ""
    var l = n
    while(ans.length<dp[n]) {
        val num = a.last { if (l-match[it]<0) false else dp[l-match[it]] == dp[l]-1 }
        ans += num
        l -= match[num]
    }
    println(ans)

}