#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[51],n,a,b,L,ok;
vector<ll> v[31];
int main(void){
    while(1){
    cin>>n;
    //cout<<n<<endl;
    if(n==0)return 0;
    ok=1;
    for(int i=0;i<31;i++)v[i]={};
    for(int i=0;i<n;i++){
        dp[i]=(1LL<<i);
    }
    for(int i=0;i<n;i++){
        cin>>a;
        for(int j=0;j<a;j++){
            cin>>b;
            v[b-1].push_back(i);
        }
    }
    for(int i=0;i<31;i++){
        L=0;
        for(auto x:v[i]){
            L|=dp[x];
        }
        if(L==(1LL<<n)-1){
            cout<<i+1<<endl;
            ok=0;
            break;
        }
        for(auto x:v[i]){
            dp[x]=L;
        }
    }
    if(ok)cout<<-1<<endl;
    }
}

