#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int solve(int n){
	bool ok[50][31]={};
	bool has[50][50]={};
	rep(i,n) has[i][i]=true;
	rep(i,n){
		int f;
		cin>>f;
		rep(j,f){
			int x;
			cin>>x;
			ok[i][x]=true;
		}
	}
	rep(i,31){
		rep(j,n){
			rep(k,n){
				if(j==k||!ok[j][i]||!ok[k][i]) continue;
				rep(s,n) has[j][s]|=has[k][s];
			}
		}
		rep(j,n){
			bool can=true;
			rep(k,n) if(!has[j][k]) can=false;
			if(can) return i;
		}
	}
	return -1;
}
int main(){
	while(true){
		int n;
		cin>>n;
		if(n==0) break;
		cout<<solve(n)<<endl;
	}
}