# Tsuruga Parking

Under, Above = 0, 1

class Car
  attr_accessor :id, :arrive, :sojourn, :park, :leave
  def initialize(id, arrival, sojourn)
    @id, @arrive, @sojourn = id, arrival, sojourn
  end
  def in(time)
    @park = time
    @leave = time + @sojourn
  end
end

until (m, n = gets.split.map(&:to_i)).all?(&:zero?)
  space = Array.new(2){Array.new(m)}
  car = n.times.map{|i| Car.new(i + 1, 10 * i, gets.to_i)}

  answer = Array.new
  head = 0
  time = 0
  until time > 12000
# space.each{|v|p v} if time%10 == 1
# p time
# exit if time > 100
    # leave
    while (i = space[Under].index{|c| c != nil && c.leave <= time})
      answer << space[Under][i].id
      space[Under][i], space[Above][i] = space[Above][i], nil
    end

    # arrive
    # empty
    while head < n && car[head].arrive <= time && (i = space[Under].index{|c| c == nil})
      space[Under][i] = car[head]
      car[head].in(time)
      head += 1
    end
    # not empty
    while head < n && car[head].arrive <= time
      diff = 121
      target = nil
      over = false
      m.times do |i|
        next if space[Above][i]
        remain = (space[Under][i].leave - time)
        if remain >= car[head].sojourn
          if over
            d = remain - car[head].sojourn
            next if diff < d
            diff = d
            target = i
          else
            over = true
            d = remain - car[head].sojourn
            diff = d
            target = i
          end
        else
          next if over
          d = car[head].sojourn - remain
          next if diff < d
          diff = d
          target = i
        end
      end
      next unless target
      space[Under][target], space[Above][target] = car[head], space[Under][target]
      car[head].in(time)
      head += 1
    end

    # update
    time += 1
    break if space.flatten.all?(&:nil?)
  end

  puts answer*" "
end