Car = Struct.new(:num, :time)

until (given = gets.split.map(&:to_i)) == [0, 0]
  m, n = given
  parking_time = n.times.map {gets.to_i}
  parking = Array.new(m) {[]}
  wait = []
  result = []
  car_num = 1
  
  loop do
    parking.map! {|space| space.map! {|car| car.time -= 10; car} }
    parking.each do |space|
      result << space.pop.num if (c = space.last) && c.time <= 0
      result << space.pop.num if (c = space.last) && c.time <= 0
    end
    
    catch :jump do
      entry = parking_time.shift
      wait << entry if entry
      loop do
        waiting = wait.first
        break unless waiting
        idx = parking.index {|space| space.empty?}
        if idx
          parking[idx] << Car.new(car_num, waiting)
        else
          throw :jump if parking.none? {|space| space.size == 1}
          left = parking.map.with_index do |space, i|
            space.size == 1 ? [space.first.time - waiting, i] : nil
          end.compact
          pos = left.select {|l| l.first >= 0}
          idx1 = if pos.empty?
            left.sort_by {|l| (-l.first).nonzero? || l.last}.first.last
          else
            pos.sort_by {|p| p.first.nonzero? || p.last}.first.last
          end
          parking[idx1] << Car.new(car_num, waiting)
        end
        wait.shift
        car_num += 1
      end
    end
    
    break if parking.all? {|space| space.empty?}
  end
  
  puts result.join(" ")
end
