n, m = gets.chomp.split.map(&:to_i)
lanes = Array.new(n){[]}
m.times{
    a, b = gets.chomp.split.map(&:to_i)
    case a
    when 0
        puts lanes[b - 1].shift
    when 1
        min = lanes.map{|ar| ar.length}.min
        i = lanes.index{|ar| ar.length == min}
        lanes[i] << b
    end
}
