import heapq import sys input=sys.stdin.readline N,M=map(int,input().split()) A=list(map(int,input().split())) T=[] for _ in range(N): T.append(list(map(int,input().split()))) hq=[] for i in range(N): for j in range(M): hq.append([j,-T[i][j],i]) hq.sort(key=lambda a:a[0]*10000+a[1]) use=[False for _ in range(N)] ans=[[] for _ in range(M)] for k in range(len(hq)): j,t,i=hq[k] t=-t if not use[i] and len(ans[t])