n, m = map(int, input().split()) A = list(map(int, input().split())) T = [list(map(int, input().split())) for _ in range(n)] row = [False] * n ans = [-1] * n for j in range(m): for i in range(n): if row[i]: continue t = T[i][j] if A[t] >= 1: A[t] -= 1 row[i] = True ans[i] = t print(*ans)