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.reverse
  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 ={
    if(k == 0) return ""
    for(ele <- caned;if( k >= COST(ele) && DP(k) - DP(k - COST(ele)) == 1) ){
      return (ele + 48).toChar + MakeReversing(k - COST(ele))
    }
    ""
  }
  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)
  }
}