import sys 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) RK = K[::-1] def check(): slis = [] wild = [] for lis in A: s = sum((k >= md) for k in lis) if(s == len(lis)): wild.append(s) else: slis.append(s) wild.sort(reverse = True) slis.sort() for i, k in enumerate(RK): s = slis[-1] if(slis) else -1 w = wild[0] if(wild) else -1 if(max(s, w) >= k): break elif(s == k - 1 and i < N - 1): slis.pop() elif(wild): wild.pop() else: return False return True ok = 0 ng = len(Alis) while(ng - ok > 1): mid = (ok + ng) >> 1 md = Alis[mid] if check(): ok = mid else: ng = mid ans = Alis[ok] print(ans)