N, M = map(int, input().split()) A = list(map(int, input().split())) T = [list(map(int, input().split())) for _ in range(N)] cnt = [0]*M ans = [-1]*N for i in range(M): for j in range(N): if ans[j] != -1: continue if cnt[T[j][i]] == A[T[j][i]]: continue cnt[T[j][i]] += 1 ans[j] = T[j][i] print(*ans)