N,M=map(int, input().split()) A=list(map(int, input().split())) ans=[-1]*N B=[] for i in range(N): C=list(map(int, input().split())) B.append(C) for j in range(M): for i in range(N): if ans[i]==-1: p=B[i][j] if A[p]>0: A[p]-=1 ans[i]=p print(*ans)