#include<iostream>
using namespace std;
struct sison{
char have[51];
char sche[31];
};
int main(){
sison sison[51];
int i,j,n,c,s,day[51],p;
while(1){
scanf("%d",&n);
if(n==0)
break;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)
sison[i].have[j]=0;
for(j=1;j<=30;j++)
sison[i].sche[j]=0;
}
for(i=1;i<=n;i++){
scanf("%d",&c);
for(j=0;j<c;j++){
scanf("%d",&s);
sison[i].sche[s]=1;
}
sison[i].have[i]=1;
}
for(p=1;p<=30;p++){
for(i=1;i<=50;i++)
day[i]=0;
for(i=1;i<=n;i++){
if(sison[i].sche[p]==0)
continue;
for(j=1;j<=n;j++){
if(sison[i].have[j]==1)
day[j]=1;
}
}
for(i=1;;i++){
if(day[i]==0)
break;
if(i==n)
goto A;
}
for(i=1;i<=n;i++){
if(sison[i].sche[p]==0)
continue;

for(j=1;j<=n;j++)
sison[i].have[j]=day[j];
}
}
A:
if(p==31){
cout<<"-1"<<endl;
}else{
printf("%d\n",p);
}
}
}