import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def f(N: Int, A: Array[Int]): Array[Int] = {
    val r = N % A.head
    if (r == 0) {
      Array.fill(N / A.head)(A.head)
    } else if (A.length > 1) {
      var a = N / A.head
      while (a >= 0) {
        val a2 = f(N - A.head * a, A.tail)
        if (a2.nonEmpty) {
          return Array.fill(a)(A.head) ++ a2
        }
        a -= 1
      }
      Array()
    } else {
      Array()
    }
  }

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val M = sc.nextInt
    val d = Array(2, 5, 5, 4, 5, 6, 3, 7, 6)
    val A = Array.fill(M)(sc.nextInt).map(i => ( d(i - 1), i)).sortBy(_._2).reverse
    val c = A.map(_._1).distinct.sorted

    val n = f(N, c)
//    println(A.mkString(", "))
    n.map(n => A.find(_._1 == n).head._2).sorted.reverse.mkString("")
  }
}
