import sys, heapq from bisect import bisect_left 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] = sorted(map(int, input().split())) st |= set(A[i]) Alis = sorted(st) def check(m): P = []; q_max = 0 for lis in A: s = len(lis) - bisect_left(lis, m) if(s < len(lis)): P.append(s) elif(q_max < s): q_max = s P.sort() if not(P): return True que = list(K[len(P):]) heapq.heapify(que) if(que and q_max >= que[0]): return True for i in range(len(P) - 1, -1, -1): u = K[i] if not(que) else min(que[0], K[i]) if(P[i] >= u): return True elif(P[i] < u - 1): return False; elif(que and P[i] == que[0] - 1 and q_max >= K[i]): return True elif(i == 0): return False elif(not(que) or P[i] < que[0] - 1): continue heapq.heapreplace(que, K[i]) return True ok = 0 ng = len(st) while(ng - ok > 1): t = (ok + ng) >> 1 if check(Alis[t]): ok = t else: ng = t ans = Alis[ok] print(ans)