n, m = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i)
ts = Array.new(n) { read_line.split.map(&.to_i) }
assign = Array.new(n, -1)
m.times do |i|
  n.times do |j|
    next if assign[j] != -1
    next if a[ts[j][i]] == 0
    a[ts[j][i]] -= 1
    assign[j] = ts[j][i]
  end
end
puts assign.join(" ")