N, M = map(int, input().split()) A = list(map(int, input().split())) T = [list(map(int, input().split())) for _ in range(N)] ok = [False] * N D = [[] for _ in range(M)] # 答え # 第k希望について行う for k in range(M): C = [[] for _ in range(M)] # 仮 # 人jについて行う for j in range(N): if not ok[j]: C[T[j][k]].append(j) # 研究室iについて行う for i in range(M): while len(D[i]) + len(C[i]) > A[i]: C[i].pop() for i in range(M): for j in C[i]: ok[j] = True D[i].append(j) ans = [0] * N for i in range(M): for j in D[i]: ans[j] = i print(*ans)