mh={
  1 => 2 ,
  2 => 5 ,
  3 => 5 ,
  4 => 4 ,
  5 => 5 ,
  6 => 6 ,
  7 => 3 ,
  8 => 7 ,
  9 => 6
}
n,m=gets.split(' ').map(&:to_i)
a=gets.split(' ').map(&:to_i)

mhu=mh.select{|k,v| a.include?(k)}
min = mhu.invert.min
mins = min[1]
minm = min[0]
keta = n / minm
n = n - minm * keta

suzi=Array.new(keta, mins)
suzi.map! do |sm|
  rtn = sm
  mhu.invert.reverse_each do |re|
    if n >= (re[0]-minm)
      n = n - (re[0]-minm)
      rtn = re[1]
      break
    end
  end
  rtn
end
p suzi.join.to_i

