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

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

a.sort!.reverse!
idx = N
ans = ""
a.each do |v|
  while dp[idx-b[v]] == dp[idx] - 1
    ans += v.to_s
    idx -= b[v]
  end
end

puts ans