N,M = map(int,input().split()) A = list(map(int,input().split())) # 定員 q = [[i, list(map(int,input().split()))[::-1]] for i in range(N)] # 希望の高いものを後ろからpop import heapq as hq hq.heapify(q) S = [[] for i in range(M)] # 各研究室に何番の生徒が入ったか while q: # 所属していない人がいる限り new_q = [] while q: i, hopes = hq.heappop(q) hope = hopes.pop() if len(S[hope]) == A[hope]: # もう入らない hq.heappush(new_q, (i, hopes)) else: S[hope].append(i) q = new_q ans = [-1] * N for i in range(M): for j in S[i]: ans[j] = i print(*ans)