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 rec = True if rec: sys.setrecursionlimit(5 * 10 ** 5) from pypyjit import set_param set_param('max_unroll_recursion=-1') n = ii() k = [i - 1 for i in li()][::-1] a = [] for _ in range(n): _ = ii() a.append(list(sorted(li(), reverse=True))) def check(x, s, ix): for i in s: if len(a[i]) > k[ix] and a[i][k[ix]] >= x: return True if len(a[i]) - 1 > k[ix] and k[ix] - 1 >= 0 and a[i][k[ix] - 1] >= x and ix + 1 < len(k): s.discard(i) ix += 1 p = check(x, s, ix) ix -= 1 s.add(i) if p: return True if len(a[i]) == k[ix] and a[i][min(len(a[i]) - 1, k[ix])] >= x: s.discard(i) ix += 1 p = check(a[i][min(len(a[i]) - 1, k[ix])], s, ix) s.add(i) ix -= 1 if p: return True if len(a[i]) < k[ix] and a[i][min(len(a[i]) - 1, k[ix])] >= x: s.discard(i) ix += 1 p = check(x, s, ix) s.add(i) ix -= 1 if p: return True return False ok = 0 ng = 10 ** 9 + 1 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if check(mid, set(range(n)), 0): ok = mid else: ng = mid print(ok)