while 1:

    N = int(input())

    if N == 0: break

    free = [list(map(int,input().split()))[1:] for i in range(N)]

    have = [set([i]) for i in range(N)]

    for day in range(1,31):

        gather = set([])

        for i in range(N):

            if day in free[i]:

                gather |= have[i]

        if len(gather) == N:

            print(day)

            break

        for i in range(N):

            if day in free[i]:

                have[i] = gather.copy()

    else:

        print(-1)

    
while 1:

    N = int(input())

    if N == 0: break

    free = [list(map(int,input().split()))[1:] for i in range(N)]

    have = [set([i]) for i in range(N)]

    for day in range(1,31):

        gather = set([])

        come = [i for i in range(N) if day in free[i]]

        for i in come:

            gather |= have[i]

        if len(gather) == N:

            print(day)

            break

        for i in come:

            have[i] = gather.copy()

    else:

        print(-1)

    
while 1:
    N = int(input())
    if N == 0:
        break
    free = [list(map(int, input().split()))[1:] for i in range(N)]
    have = [set([i]) for i in range(N)]
    for day in range(1, 31):
        gather = set([])
        for i in range(N):
            if day in free[i]:
                gather |= have[i]
        if len(gather) == N:
            print(day)
            break
        for i in range(N):
            if day in free[i]:
                have[i] = gather.copy()
    else:
        print(-1)

while 1:
    N = int(input())
    if N == 0:
        break
    free = [list(map(int, input().split()))[1:] for i in range(N)]
    have = [set([i]) for i in range(N)]
    for day in range(1, 31):
        gather = set([])
        come = [i for i in range(N) if day in free[i]]
        for i in come:
            gather |= have[i]
        if len(gather) == N:
            print(day)
            break
        for i in come:
            have[i] = gather.copy()
    else:
        print(-1)

-        for i in range(N): -            if day in free[i]: -                gather |= have[i] +        come = [i for i in range(N) if day in free[i]] +        for i in come: +            gather |= have[i] -        for i in range(N): -            if day in free[i]: -                have[i] = gather.copy() +        for i in come: +            have[i] = gather.copy()