#include <iostream>
#include <algorithm>
#include <vector>
using namespace std; 

int solve(int n, vector<vector<int> >& sched) {
    vector<long long> f(31, 0);

    for (int j = 0; j < n; ++j) {
        for (int k = 0; k < sched[j].size(); ++k) {
            if (sched[j][k]) {
                f[sched[j][k]] |= (1LL << j);
            }
        }
    }

    for (int j = 1; j <= 30; ++j) {
        long long t = f[j];
        for (int k = j-1; k > 0; --k) {
            if (t & f[k]) {
                t |= f[k];
            }
        }

        if (t == (1LL << n) - 1) {
            return j;
        }
    }

    return -1;
}

int main() {
    int n;
    vector<vector<int>> sched;
    while (true) {
        cin >> n;
        if (n == 0) break;
        sched.resize(n);
        for (int j = 0; j < n; ++j) {
            int l;
            cin >> l; sched[j].resize(l);
            for (int k = 0; k < l; ++k) {
                cin >> sched[j][k];
            }
        }
        cout << solve(n, sched) << endl;
    }
    return 0;
}