open Printf open Scanf
open Array

let cost = [|0;2;5;5;4;5;6;3;7;6|]

let () = scanf " %d %d" @@ fun n m ->
  let a = init m (fun _ -> scanf " %d" @@ fun v -> v) in
  let maxstr u v =
    match compare (String.length u) (String.length v) with
    |  1 -> u
    | -1 -> v
    | _ -> max u v
  in
  let dp = make (n+1) "" in
  dp.(n) <- "0";
  for j=n downto 0 do
    if dp.(j) <> "" then (
      iter (fun i ->
        let c = cost.(i) in
        if j-c >= 0 then
          dp.(j-c) <- maxstr
            dp.(j-c)
            (dp.(j) ^ (string_of_int i))
      ) a
    )
  done;
  (* iter (print_endline) dp; *)
  print_string @@ String.(sub dp.(0) 1 (length dp.(0) - 1))
