#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
const int V = 60;
int n;
vector<int> sche[31];
set<int> have[V];

int solve(){
  for(int i=0;i<n;++i) have[i].insert(i);
  for(int i=1;i<=30;++i){
    for(int j=0;j<sche[i].size();++j)
      for(int k=0;k<sche[i].size();++k)
	for(set<int>::iterator it = have[sche[i][k]].begin(); it!=have[sche[i][k]].end();++it)
	  have[sche[i][j]].insert(*it);
    for(int j=0;j<n;++j)
      if(have[j].size()==n) return i;
  }
  return -1;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;++i) have[i].clear();
    for(int i=0;i<=30;++i) sche[i].clear();
    for(int i=0;i<n;++i){
      int a; cin >> a;
      while(a--){
	int d;cin >> d;
	sche[d].push_back(i);
      }
    }
    cout << solve() << endl;
  }
  
  return 0;
}