n,m=map(int,input().split()) a=list(map(int,input().split())) t=[list(map(int,input().split())) for i in range(n)] r=[-1]*n for j in range(m): for i in range(n): if r[i]!=-1: continue if a[t[i][j]]>0: r[i]=t[i][j] a[t[i][j]]-=1 print(*r)