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

int main(void)
{
    int n;
    int f;
    int s[31][52];
    int s2[31][52];
    int m[51];
    int p, d;
    int i, j, k, l;
    int cnt;
    int min;
    int flag;

    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;
            }
        }
        
        min = 31;
        for (l = 1; l <= n; l++){
            memcpy(s2, s, sizeof(s));
            for (j = 1; j <= 30; j++){
                if (s2[j][l] == 1){
                    s2[j][l] = 2;
                }
            }
            do {
                flag = 0;
                for (i = 1; i <= d; i++){
                    for (j = 1; j <= n; j++){
                        if (s2[i][j] == 2){
                            break;
                        }
                    }
                    if (j <= n){
                        for (j = 1; j <= n; j++){
                            if (s2[i][j] == 1){
                                for (k = i; k <= 30; k++){
                                    if (s2[k][j] == 1){
                                        s2[k][j] = 2;
                                    }
                                }
                                flag = 1;
                            }
                        }
                    }
                }
            } while (flag != 0);
            
            memset(m, 0, sizeof(m));
            for (i = 1; i <= 30; i++){
                for (j = 1; j <= n; j++){
//printf("[%d]", s2[i][j]);
                    if (s2[i][j] == 2){
                        m[j] = 1;
                    }
                }
//printf("\n");
                cnt = 0;
                for (j = 1; j <= n; j++){
                    cnt += m[j];
                }
                if (cnt == n && min > i){
                    min = i;
                }
            }
//printf("\n");
        }
        if (min <= 30){
            printf("%d\n", min);
        }
        else {
            printf("-1\n");
        }
    }
    return (0);
}