#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int n;
bitset<50> dp[50];
vector< vector<bool> > d;

int solve() {
    for (int i = 0; i < n; i++) {
        dp[i].reset();
        dp[i].set(i);
    }

    for (int i = 1; i <= 30; i++) {
        bitset<50> bs(0);
        for (int j = 0; j < n; j++) {
            if (d[j][i]) {
                bs |= dp[j];
            }
        }

        if (bs.count() == n) {
            return i;
        }

        for (int j = 0; j < n; j++) {
            if (d[j][i]) {
                dp[j] = bs;
            }
        }
    }

    return -1;
}

int main() {
    while (cin >> n, n) {
        d.resize(50, vector<bool>(31));
        for (int i = 0; i < 50; i++) {
            for (int j = 1; j <= 30; j++) {
                d[i][j] = false;
            }
        }
        for (int i = 0; i < n; i++) {
            int a;
            cin >> a;
            for (int j = 0; j < a; j++) {
                int b;
                cin >> b;
                d[i][b] = true;
            }
        }

        cout << solve() << endl;
    }

    return 0;
}