#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)

#define MAX_N 50
#define MAX_D 31

int n;
bool schedule[MAX_N][MAX_D];
set<int> check[MAX_N];

int main() {
	while(cin>>n, n) {
	    rep(i, MAX_N) memset(schedule[i], false, MAX_D);
	    rep(i, MAX_N) check[i] = { i };
	    rep(i, n) {
	        int f; cin >> f;
	        rep(_, f) { int d; cin>>d; schedule[i][d] = true; }
	    }
	    int ans = -1;
	    REP(d, 1, MAX_D) {
	        set<int> tmp;
	        rep(i, n) if(schedule[i][d]) for(int k: check[i]) tmp.insert(k);
	        rep(i, n) if(schedule[i][d]) for(int k: tmp) check[i].insert(k);
	        if(tmp.size()==n) ans = d;
	        if(ans!=-1) break;
	    }
        cout << ans << endl;
	}
}

