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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	for(int n; cin >> n, n;) {
		vector<int> schedule(n, 0);
		for(int i = 0; i < n; ++i) {
			int m;
			cin >> m;
			for(int j = 0; j < m; ++j) {
				int day;
				cin >> day;
				schedule[i] |= (1 << day);
			}
		}

		vector<long long> map(n);
		for(int i = 0; i < n; ++i)
			map[i] = (1ll << i);

		for(int day = 1; day <= 30; ++day) {
			for(int i = 0; i < n; ++i)
				if(schedule[i] & (1 << day))
					for(int j = i + 1; j < n; ++j)
						if(schedule[j] & (1 << day))
							map[i] = map[j] = (map[i] | map[j]);

			if(find(map.begin(), map.end(), (1ll << n) - 1) != map.end()) {
				cout << day << endl;
				goto success;
			}
		}

		cout << -1 << endl;
	success:;
	}

	return EXIT_SUCCESS;
}