# -*- coding: utf-8 -*- """ Created on Thu Mar 21 00:02:29 2024 @author: Tekyla """ #from sys import stdin #input = lambda :stdin.readline()[:-1] from collections import deque N,M = map(int, input().split()) A = list(map(int, input().split())) ans = [-1 for _ in range(N)] T = [list(map(int, input().split())) for _ in range(N)] i = 0 d1 = deque(list(range(N))) d2 = deque() while d1: while d1: student = d1.popleft() t = T[student][i] if A[t] > 0: ans[student] = t A[t] -= 1 else: d2.append(student) d1 = d2 d2 = deque() i += 1 print(*ans)