n = int(input()) K = list(map(int, input().split())) A = [[] for _ in range(n)] for i in range(n): input() A[i] = list(map(int, input().split())) def ok(x): C = [sum(a >= x for a in row) for row in A] C.sort() tf = False for c, k in zip(C, K): if tf: c += 1 tf = c >= k return tf l = 1 r = 1 << 30 while r - l > 1: mid = (l + r) // 2 if ok(mid): l = mid else: r = mid print(l)