st = gets.chomp!.split(" ")
n = st[0].to_i

st = gets.chomp!.split(" ")
s = st.size-1
AMO = [nil,2,5,5,4,5,6,3,7,6]
num = Hash.new
ans = ""

for i in 0..s
    num[AMO[st[i].to_i]] = st[i].to_i
end

num = num.sort{|a,b| a[0] <=> b[0]}

if n >= num[0][0]
    (n/num[0][0]).times do
        ans += "#{num[0][1]}"
    end
end

n %= num[0][0]
x = num[0][0]
y = num[0][1]

num = num.sort{|a,b| -a[1] <=> -b[1]}
i = 0
j = 0

while n != 0 
    if x == num[i][0]
        break
    end

    if n < num[i][0] - x
        i += 1
        next
    end

    ans[j] = "#{num[i][1]}"
    j += 1
    n -= num[i][0] - x
end

num = num.sort{|a,b| -a[0] <=> -b[0]}
i = 0
j = ans.size-1

while n != 0
    if n < num[i][0] - x || y <= num[i][1]
        i += 1
        next
    end

    ans[j] = "#{num[i][1]}"
    j -= 1
    n -= num[i][0] - x
end

puts ans
