module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = map(map int . words) . lines
printer = unlines . (:[]) 

cost = [ 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ]

solver ([n,m]:ds:[]) = concatMap show ans
  where
    dif (a1,a2) (b1,b2) = if a1==b1 then compare b2 a2 else compare a1 b1
    ps1 = L.sortBy dif [(cost!!d,d) |d <- ds]
    ans = reverse $ L.sort $ head $ dfs [] n ps1

dfs :: [Int] -> Int -> [(Int,Int)] -> [[Int]]
dfs sq n ps
  | n == 0 = [sq]
  | otherwise = concat [dfs (d:sq) (n-c) ps  | (c,d) <- ps, n-c >= 0]  
    

