N,M = map(int, input().split()) A = list(map(int, input().split())) T = [list(map(int, input().split())) for _ in range(N)] R = list(range(N)) ANS = [0]*N for i in range(M): NR = [] for r in R: if A[T[r][i]]>0: ANS[r]=T[r][i] A[T[r][i]]-=1 else: NR.append(r) R = NR print(*ANS)