N,M = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = [0,2,5,5,4,5,6,3,7,6]

a.sort_by!{|v| [b[v],-v]}
c,d = a[0],b[a[0]]
dp = []*(N+1)
dp[0] = 0

1.upto(N) do |i|
  tmp = []
  a.each do |v|
    tmp << dp[i-b[v]] + 1 if i >= b[v] && !dp[i-b[v]].nil?
  end
  dp[i] = tmp.empty? ? nil : tmp.max
end

ans = c.to_s*dp[N]
ex = N - dp[N] * d

a.sort!.reverse!
l,r = 0,ans.length-1
a.each do |v|
  diff = b[v]-d
  if ex >= diff && v > c
    cnt = ex/diff
    ans[l,cnt] = v.to_s * cnt
    l += cnt
    ex %= diff
  end
end
a.sort_by!{|v| [-b[v],-v]}
a.each do |v|
  diff = b[v]-d
  if ex >= diff && v < c
    cnt = ex/diff
    ans[r-ex/b[v],cnt] = v.to_s * cnt
    r -= cnt
    ex %= diff
  end
end
puts ans
