import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 from collections import deque import bisect import heapq class Heap(): def __init__(self, maxi = False): self.sum = 0 self.al = [] self.maxi = maxi self.len = 0 def __len__(self): return len(self.al) def add(self, x): if self.maxi: heapq.heappush(self.al, -x) else: heapq.heappush(self.al, x) self.sum += x def pop(self): if self.maxi: now = heapq.heappop(self.al) self.sum += now return -now else: now = heapq.heappop(self.al) self.sum -= now return now def top(self): now = self.pop() self.add(now) return now n = ii() k = li() a = [] for _ in range(n): _ = ii() a.append(list(sorted(li()))) def check(x): p = [] q_max = 0 for v in a: gt = len(v) - bisect.bisect(v, x) if gt < len(v): p.append(gt) elif q_max < gt: q_max = gt if not p: return True p.sort() que = Heap() for v in k[len(p):]: que.add(v) if(que and q_max >= que.top()): return True for i in range(len(p) - 1, -1, -1): u = k[i] if len(que) == 0 else min(que.top(), k[i]) if(p[i] >= u): return True elif(p[i] < u - 1): return False elif(len(que) and p[i] == que.top() - 1 and q_max >= k[i]): return True elif(i == 0): return False elif(len(que) == 0 or p[i] < que.top() - 1): continue que.pop() que.add(k[i]) return True A = [] for i in range(n): for v in a[i]: A.append(v) A = list(set(A)) A.sort() ok = 0 ng = len(A) while abs(ok - ng) > 1: mid = (ok + ng) // 2 if check(A[mid]): ok = mid else: ng = mid print(A[ok+1])