N = gets.to_i
lst = gets.split(' ').map(&:to_i).uniq.sort

# 対象の数字に必要なマッチ棒の本数を返却
rep = lambda { |n|
  h = {'1' => 2, '2' => 5, '3' => 5, '4' => 4, '5' => 5,
     '6' => 6, '7' => 3, '8' => 7, '9' => 6}
  h[n.to_s]
}

n_h = lst.map { |e| [rep.call(e), e] }
        .group_by { |e| e[0] }
        .map { |e| [e[0], e[1].map{ |e2| e2[1] }.max] }
        .to_h

# 対象のマッチ棒の本数で可能な最大の数字を返却
get_num = lambda { |n|
  r = n_h[n]
  r.nil? ? 0 : r
}

min = lst[0]
lst.each_with_index do |n, i|
  min = n if min < n && rep.call(min) >= rep.call(n)
end

ret = (min.to_s * (N / rep.call(min)))
amari = N % rep.call(min)

if amari == 0
  exit
end

num = amari + rep.call(min)
idx = -1
loop do
  idx += 1
  max = min
  (num).downto(rep.call(min) + 1) do |i|
    max = get_num.call(i) if max < get_num.call(i)
  end

  if max == min
    (num).downto(rep.call(min) + 1) do |i|
      max = get_num.call(i) if 0 < get_num.call(i)
      if i == num
        break
      end
    end
  end

  ret[idx] = max.to_s

  if num - rep.call(max) == 0
    break
  else
    num = num - rep.call(max) + rep.call(min)
  end
end

p ret.split('').sort.reverse.join.to_i