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