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 caned : Array[Int] = can.sorted
  val COST : Array[Int] = Array(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
  val DP : Array[Int] = Array.fill(n + 10)(-1)
  DP(0) = 0

  def MakeReversing(k : Int): String ={
    def getNextString(u : Int): (Char, Int) ={
      var res1 : Char = '\n'
      var res2 : Int = 114514
      for(ele <- caned;if(u >= COST(ele))){
        if(DP(u) - DP(u - COST(ele)) == 1) {
          res1 = ('0' + ele).toChar
          res2 = COST(ele)
        }
      }
      (res1, res2)
    }
    var search : Int = k
    var res : String = ""
    while(search > 0){
      val (a, b) : (Char, Int) = getNextString(search)
      search -= b
      res = res + a
    }
    res
  }
  def solve(k : Int): String ={
    for(i <- 0 until k; j <- can){
      val idx : Int = i + COST(j)
      if(DP(idx) < DP(i) + 1) DP(idx) = DP(i) + 1
    }
    MakeReversing(k)
  }
}