n, m  = gets.strip.split.map(&:to_i)
as = gets.strip.split.map(&:to_i)

matched_numbers = [2,5,5,4,5,6,3,7,6].map.with_index {|e,i| [e, i+1] }.select{|_,i| as.include?(i) }.sort.to_h

#p matched_numbers

dp = Array.new(n+1)

(1..n).each do |i|
  tmp = matched_numbers[i].to_i.to_s
  matched_numbers.each do |cost, number|
    next if dp[i-cost].nil? || dp[i-cost].to_i.zero?

    a = dp[i-cost]
    b = number.to_s
    str = a>b ? (a+b) : (b+a)
    tmp = str if str.length > tmp.length || (tmp.length == str.length && str> tmp )
  end
  dp[i] = tmp
end

#p dp
p dp[n].to_i