# 問題通りにシミュレーション N, M = map(int, input().split()) A = list(map(int, input().split())) T = [] for i in range(N): temp = list(map(int, input().split())) T.append(temp) remaining = [] for a in A: remaining.append(a) ans_list = [-1]*N for j in range(M): for i in range(N): if ans_list[i] == -1: if remaining[T[i][j]]>0: remaining[T[i][j]] -= 1 ans_list[i] = T[i][j] print(*ans_list)