#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

ll n;
int a[50][50];
ll s[50];

ll f(){
	rep(d,1,31){
		ll temp=0;
		rep(i,0,n)if(a[i][d])temp|=s[i];
		rep(i,0,n)if(a[i][d])s[i]=temp;
		if(temp==(1LL<<n)-1)return d;
	}
	return -1;
}

int main(){
	while(scanf("%lld",&n),n){
		rep(i,0,50)rep(j,0,50)a[i][j]=0;
		rep(i,0,50)s[i]=1LL<<i;
		rep(i,0,n){
			ll m;
			scanf("%lld",&m);
			rep(j,0,m){
				ll t;
				scanf("%lld",&t);
				a[i][t]=1;
			}
		}
		printf("%lld\n",f());
	}
}
