n,m=gets.chomp.split(' ').map(&:to_i)
a=gets.chomp.split(' ').map(&:to_i)
arr=[0,2,5,5,4,5,6,3,7,6]
min = 100
min1=100
minkey=0
a=a.sort
a.each do |i|
  if arr[i] < min
    min = arr[i]
    minkey = i
  end
end
dig=n/min
res=n%dig
parts=a.map do |i|
  arr[i]%min
end
count=0
result0 = 0
result1= 0
dig1=0
parts.each do |i|
  if i == 0
    count+=1
    next
  end
  if i ==res
    result0=a[count]
  end
  if res%i==0
    dig1 = res/i
    if (dig1)<min1
    result1=a[count]
    end
  end
    count+=1
end
str=""
  if result0 == 0
    if result1<minkey
      dig.times{str+=minkey.to_s}
      dig1.times{str+=result1.to_s}
    else
      dig1.times{str+=result1.to_s}
            dig.times{str+=minkey.to_s}
    end
  else
    if result0<minkey
      dig.times{str+=minkey.to_s}
      str+=result0.to_s
    else
      str+=result0.to_s
      dig.times{str+=minkey.to_s}
    end
    puts str