io = STDIN
N,_=io.gets.split.map(&:to_i)
a=io.gets.split.map(&:to_i)
#     1 2 3 4 5 6 7 8 9
$ar=[0,2,5,5,4,5,6,3,7,6]
$dp=Array.new(N+1,0)
a.each do |num|
  m=$ar[num]
  $dp[m]=[$dp[m],num].max
end
def calc(i,j)
  is= $dp[i].to_s.size
  js= $dp[j].to_s.size
  if is>js
    rtn=$dp[i]*10*js+$dp[j]
  elsif is<js
    rtn=$dp[j]*10*is+$dp[i]
  else
    if $dp[i]>= $dp[j]
      rtn=$dp[i]*10*js+$dp[j]
    else
      rtn=$dp[j]*10*is+$dp[i]
    end
  end
  rtn
end
def gen(i,j)
  return if i+j>N
  return if $dp[i]==0
  $dp[i+j]=[calc(i,j),$dp[i+j]].max
  return if i == j || i+1 == j
  gen(i+1,j-1)
end
start=$dp.index{|x|x>0}
(1..N).each do |n|
  next if n<start
  gen(start,n)
end
p $dp[N]
