x = {
  1 => 2,
  7 => 3,
  4 => 4,
  5 => 5,
  3 => 5,
  2 => 5,
  9 => 6,
  6 => 6,
  8 => 7,
}

@y = {}
@flag = false

@n, @m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

x.each do |i, j|
  @y[j] = i if a.include?(i) && @y[j].nil?
end

@z = @y.keys

def calc(sum, i)
  nokori = @n - sum
  cost = @z[i-1]


  if (nokori % cost) == 0
    @flag = true
    return [@y[cost].to_s * (nokori / cost)]
  end
  if i == @z.count
    return
  end

  (0..(nokori / cost)).reverse_each do |j|
    tmp = calc(sum + cost * j ,i + 1)
    return [@y[cost].to_s * j] + tmp if @flag
  end
end

puts calc(0, 1).sort.reverse.join