object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt
  val a = Array.fill(m)(sc.nextInt)

  val alts = Map(
    1 -> 2,
    2 -> 5,
    3 -> 5,
    4 -> 4,
    5 -> 5,
    6 -> 6,
    7 -> 3,
    8 -> 7,
    9 -> 6
  ).filter(i => a.contains(i._1)).toList.sortBy(-_._1)

  val dp = Array.fill(n + 1)(-1)
  dp(0) = 0

  for (i <- 1 to n) {
    dp(i) = {
      val next = alts.filter(_._2 <= i).map{ alt =>
        if (dp(i - alt._2) == -1) -1
        else dp(i - alt._2) + 1
      }
      if (next.size == 0) -1 else next.max
    }
  }

  val ans = Array.fill(dp(n))(0)
  var rest = n

  for (i <- 0 until dp(n)) {
    val next = alts.filter(_._2 <= rest)
      .find(i => dp(rest - i._2) == dp(rest) - 1).get
    ans(i) = next._1
    rest -= next._2
  }

  println(ans.mkString(""))
}