def dfs(n,v,s)
  return nil if n<0
  if v==V.size
    return n.zero? ? s : nil
  end
  c=V[v]
  res=dfs(n-B[c], v+1, s+c.to_s)
  return res if res
  dfs(n, v+1, s)
end

B=[0,2,5,5,4,5,6,3,7,6]

N,M=gets.split.map(&:to_i)
A=gets.split.map(&:to_i)

S=Hash.new{|h,k|h[k]=0}
A.each do |a|
  S[B[a]]=[S[B[a]],a].max
end

K=S.keys.sort
V=S.values.sort.reverse

n,r=N.divmod(K[0])
if r.zero?
  puts S[K[0]].to_s*n
  exit
end

until n.zero?
  n-=1
  r+=K[0]
  ok=dfs(r,0,"")
  next unless ok
  i=0
  ok.chars.each do |c|
    i+=1 if S[K[0]].to_s<c
  end
  print ok[0...i]
  print S[K[0]].to_s*n
  print ok[i..-1]
  puts
  exit
end
