object Main extends App {
  import scala.io.StdIn._

  val usage = Array(2, 5, 5, 4, 5, 6, 3, 7, 6)
  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val a = readLine.trim.split(' ').map(_.toInt)
  println(solve(n, a).mkString)
  def solve(n: Int, canUse: Array[Int]): List[Int] = {
    val minUse = canUse.map(i ⇒ usage(i - 1)).min
    val maxDigit = n / minUse
    val numbers = canUse.sorted(Ordering.Int.reverse)
    val memo = Array.tabulate(n + 1){_ ⇒ State(-1, 0)}
    memo(0).length = 0
    for (i ← 0 to n if memo(i).length != -1){
      for (number ← numbers if i + usage(number - 1) <= n){
        if (memo(i + usage(number - 1)).length < memo(i).length + 1) {
          memo(i + usage(number - 1)).length = memo(i).length + 1
          memo(i + usage(number - 1)).head = number
        }else if (memo(i + usage(number - 1)).length == memo(i).length + 1 && memo(i + usage(number - 1)).head < number){
          memo(i + usage(number - 1)).head = number
        }
      }
    }
    var using = n
    var result = Nil: List[Int]
    while (using != 0){
      result ::= memo(using).head
      using -= usage(memo(using).head - 1)
    }
    result.reverse
  }
  case class State(var length: Int, var head: Int)
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }

}