N, M = map(int, input().split()) A = list(map(int, input().split())) tab = [] for _ in range(N): tab.append(list(map(int, input().split()))) rooms = [0] * M ans = [-1] * N used = set() for k in range(M): # 第 k 希望 for i in range(N): # 学生 if i in used: continue r = tab[i][k] if rooms[r] + 1 <= A[r]: ans[i] = r rooms[r] += 1 used.add(i) print(*ans)