open Printf open Scanf
open Array

let cost = [|0;2;5;5;4;5;6;3;7;6|]
let cmpstr u v =
  let c = String.(Pervasives.compare (length u) (length v)) in
  if c <> 0 then c
  else
    let l = String.length u in
    let rec f i =
      if i=l then 0
      else
        let c = compare u.[i] v.[i] in
        if c<>0 then c
        else f (i+1)
    in f 0
let maxstr u v = match cmpstr u v with
| 0 | -1 -> v
| _ -> u

let () = scanf " %d %d" @@ fun n m ->
  let a = init m (fun _ -> scanf " %d" @@ fun v -> v) in
  let d = n/2 in
  let dp = make_matrix (d+3) (n+1) "" in
  dp.(0).(n) <- "0";
  for i=1 to d+1 do
    for j=n downto 1 do
      if String.length dp.(i-1).(j) <> 0 then (
        iter (fun k ->
          if j-cost.(k) >= 0 then (
            dp.(i).(j-cost.(k)) <-
              maxstr
                dp.(i).(j-cost.(k))
                (dp.(i-1).(j) ^ (string_of_int k))
          )
        ) a
      )
    done;
  done;
  let mx =
    let mx = ref "" in
    iter (fun b ->
      mx := maxstr !mx b.(0)
    ) dp; !mx
  in
  print_string @@
    String.sub mx 1 (String.length mx - 1)

