IN = open('moose.in')
out = open('moose.out', 'w').write
n = int(IN.readline())

def select(a, now):
    b = filter(lambda x: x >= now, a)
    return None if len(b) == 0 else min(b)

now = 0
for i in range(n - 1):
    a = select(map(int, IN.readline().split())[1:], now)
    if a == None:
        out("-1")
        exit(0)
    else:
        now = a

a = max(map(int, IN.readline().split())[1:])
if a < now:
    out("-1")
else:
    out("%d"%a)