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) ok = 0 ng = len(Alis) def check(): B = sorted([(sum((k >= md) for k in lis), len(lis)) for lis in A]) for k in K[::-1]: if(B[-1][0] >= k): return True elif(len(B) == 1): return (B[-1][0] == B[-1][1]) elif(B[-1][0] < k-1): break B.pop() return False while(ng - ok > 1): mid = (ok + ng) >> 1 md = Alis[mid] if check(): ok = mid else: ng = mid ans = Alis[ok] print(ans)