#include <bits/stdc++.h>
using namespace std;
using LL=long long;

int main(){
    int n;
    cin >> n;
    while(n != 0){
    vector<vector<int>> s(30);
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        for(int j=0; j<x; j++){
            int f;
            cin >> f;
            f--;
            s[f].push_back(i);
        }
    }
    vector<LL> b(n, 0);
    int ans = -1;
    for(int i=0; i<n; i++){
        b[i] |= (1LL << i);
    }

    for(int i=0; i<30; i++){
        LL tmp = 0;
        for(auto &&x : s[i]){
            tmp |= b[x];
        }
        for(auto &&x : s[i]){
            b[x] |= tmp;
        }
        if(tmp == (1LL<<n)-1){
            ans = i+1;
            break;
        }
    }
    cout << ans << endl;
    cin >> n;
    }
}







