def Map(): return list(map(int,input().split())) N,M = Map() A = Map() T = [Map() for i in range(N)] ans = [-1 for i in range(N)] for m in range(M): for i in range(N): if ans[i] != -1: continue t = T[i][m] if A[t] > 0: A[t] -= 1 ans[i] = t print(*ans)