import scala.io.StdIn.readLine

object Main{
  def main(args : Array[String]): Unit ={
    val Array(n, m) : Array[Int] = readLine().split(' ').map(_.toInt)
    val can : Array[Int] = readLine().split(' ').map(_.toInt)
    val SLV = new SOLVE(n, can)
    println(SLV.solve(n))
  }
}

class SOLVE(private val n : Int, private val can : Array[Int]){
  val COST : Array[Int] = Array(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
  val DP : Array[BigInt] = Array.fill(n + 10)(-1)
  DP(0) = 0
  def solve(k : Int): BigInt ={
    /*
    if(DP(k) != -1) DP(k)
    else{
      for(ele <- can){
        val idx = k - COST(ele)
        if(idx >= 0) if(DP(k) < ele + 10 * solve(idx)) DP(k) = ele + 10 * solve(idx)
      }
    }
    DP(k)
    */
    for(i <- 0 until k; j <- can){
      val idx : Int = i + COST(j)
      if(DP(idx) < 10 * DP(i) + j) DP(idx) = 10 * DP(i) + j
    }
    DP(k)
  }
}