n = gets.split[0].to_i

match_table = (1..9).to_a.zip([2,5,5,4,5,6,3,7,6]).to_h

digits = gets.split.map(&:to_i)

lookup_table = [2,5,5,4,5,6,3,7,6].zip((1..9).to_a).select do |a|
  digits.include?(a[1])
end.group_by {|a| a[0]}.map do |k, v|
  [k, v.map {|a| a[1]}.max]
end.to_h

how_matches = digits.map do |digit|
  match_table[digit]
end.sort

def test(n, nums)
  return if (!nums) or nums.empty?
  divisor = nums[0]
  q = n.div(divisor)
  r = n % divisor
  if r == 0
    Array.new(q, divisor)
  elsif nums.include?(r)
    Array.new(q, divisor) + [r]
  else
    list = nums[1..-1]
    (1..q).each do |i|
      res = test(n - divisor * (q - i), list)
      if res.kind_of?(Array) && !res.empty?
        return Array.new(q - i, divisor) + res
      end
    end
  end
end

ans = test(n, how_matches).map do |i|
  lookup_table[i]
end.sort.reverse.join('')

puts ans