class Car
  num = 1
  
  define_method(:initialize) do |time|
    @num = num
    num += 1
    @time = time
  end
  attr_accessor :num, :time
  
  define_singleton_method(:clear) {num = 1}
end

class ParkingLot
  Space = Struct.new(:upper, :lower)
  
  def initialize(num)
    @spaces = num.times.map {|i| Space.new}
  end
  
  def add(waiting_time)
    idx = @spaces.index {|sp| sp.lower.nil?}
    if idx
      @spaces[idx].lower = Car.new(waiting_time)
    else
      return false if @spaces.all? {|sp| sp.upper}
      
      idxs = @spaces.map.with_index {|sp, i| i if sp.lower && !sp.upper}.compact
      idx = idxs.map do |i|
        diff = @spaces[i].lower.time - waiting_time
        diff >= 0 ? [diff, i] : nil
      end.compact.sort.first&.last
      unless idx
        idx = idxs.map {|i| [waiting_time - @spaces[i].lower.time, i]}.sort.first.last
      end
      
      @spaces[idx].upper = @spaces[idx].lower.dup
      @spaces[idx].lower = Car.new(waiting_time)
    end
    true
  end
  
  def next
    @spaces.each do |sp|
      if sp.lower
        sp.lower.time -= 10
        sp.upper.time -= 10 if sp.upper
      end
    end
    
    result = []
    @spaces.each do |sp|
      if sp.lower and sp.lower.time <= 0
        result << sp.lower.num
        sp.lower = sp.upper.dup
        sp.upper = nil
      end
    end
    @spaces.each do |sp|
      if sp.lower and sp.lower.time <= 0
        result << sp.lower.num
        sp.lower = nil
      end
    end
    
    result
  end
  
  def empty?
    @spaces.all? {|sp| sp.lower.nil?}
  end
end

until (given = gets.split.map(&:to_i)) == [0, 0]
  m, n = given
  parking_time = n.times.map {gets.to_i}
  pl = ParkingLot.new(m)
  result = []
  wait = []
  Car.clear
  
  loop do
    result += pl.next

    wait << parking_time.shift
    while (waiting = wait.shift)
      unless pl.add(waiting)
        wait.unshift(waiting)
        break
      end
    end
    
    break if pl.empty?
  end
  
  puts result.join(" ")
end

