#include <stdio.h>
#include <string.h>

int main(void)
{
    int n;
    int f;
    int s[31][51];
    int p, d;
    int i, j;
    int cnt;
    
    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }
        
        memset(s, 0, sizeof(s));
        
        for (i = 1; i <= n; i++){
            scanf("%d", &p);
            for (j = 0; j < p; j++){
                scanf("%d", &d);
                s[d][i] = 1;
            }
        }
        
        cnt = 0;
        for (i = 1; i <= n; i++){
            if (s[1][i] == 1){
                s[1][i] = 2;
                s[0][i] = 1;
                cnt++;
            }
        }
        if (cnt == n){
            printf("1\n");
            continue;
        }
        
        for (i = 2; i <= 30; i++){
            for (j = 1; j <= n; j++){
                if (s[i][j] == 1 && s[i - 1][j] == 2){
                    break;
                }
            }
            if (j <= n){
                for (j = 1; j <= n; j++){
                    if (s[i][j] == 1){
                        s[i][j] = 2;
                        s[0][j] = 1;
                    }
                }
                cnt = 0;
                for (j = 1; j <= n; j++){
                    if (s[0][j] == 1){
                        cnt++;
                    }
                }
                if (cnt == n){
                    printf("%d\n", i);
                    break;
                }
            }
        }
        if (i > 30){
            printf("-1\n");
        }
    }
    return (0);
}