import sys from collections import defaultdict as dfdict input = sys.stdin.readline N = int(input()) K = list(map(int, input().split())) T = [0] * N A = [[] for _ in [0] * N] st = set([]) for i in range(N): T[i] = int(input()) A[i] = list(map(int, input().split())) st |= set(A[i]) Alis = sorted(st) ok = 0 ng = len(Alis) def check(): dic = dfdict(int) wild = [] for lis in A: s = sum((k >= md) for k in lis) if(s == len(lis)): wild.append(s) else: dic[s] += 1 wild.sort(reverse = True) slis = sorted(dic.keys()) for i, k in enumerate(K[::-1]): s = slis[-1] if(slis) else -1 w = wild[0] if(wild) else -1 if(max(s, w) >= k): break elif(s == k - 1): dic[s] -= 1 if(dic[s] == 0): slis.pop() elif(wild): wild.pop() else: return False return True while(ng - ok > 1): mid = (ok + ng) >> 1 md = Alis[mid] if check(): ok = mid else: ng = mid ans = Alis[ok] print(ans)