import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n,m = map(int,input().split()) a = list(map(int,input().split())) t = [list(map(int,input().split()))[::-1] for i in range(n)] now = [[] for i in range(m)] left = [i for i in range(n)] for i in range(m): for i in left: if not t[i]: continue x = t[i].pop() now[x].append(i) new = [] for i in range(m): while len(now[i]) > a[i]: new.append(now[i].pop()) left = new left.sort() ans = [0]*n for i in range(m): for j in now[i]: ans[j] = i print(*ans)