#include <iostream>
using namespace std;

int main()
{
    int f, n, t;
    while (true) {
        bool schedule[50][31] = {};
        long long maps[50];
        cin >> n;
        if (n == 0) {
            break;
        }
        for (int i = 0; i < n; i++) {
            cin >> f;
            for (int j = 0; j < f; j++) {
                cin >> t;
                schedule[i][t] = true;
            }
        }
        
        for (int i = 0; i <n; i++) {
            maps[i] = 1LL << i;
        }
        
        int ans = -1;
        long long gather;
        for (int t = 1; t <= 30; t++) {
            gather = 0;
            for (int i=0; i < n; i++) {
                if (schedule[i][t]) {
                    gather |= maps[i];
                }
            }
            for (int i=0; i < n; i++) {
                if (schedule[i][t]) {
                    maps[i] = gather;
                }
            }
            if (gather == (1LL << n) - 1){
                ans = t;
                break;
            }
        }
        cout << ans << endl;
        
    }
    return 0;
}