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

int main()
{
	int n;
	while (cin >> n, n) {
		vector<vector<int>> v(31);
		for (int i = 0, f; i < n; i++) {
			cin >> f;
			for (int j = 0, d; j < f; j++) {
				cin >> d;
				v[d - 1].push_back(i);
			}
		}
		vector<vector<int>> dp(n, vector<int>(n));
		for (int i = 0; i < n; i++) {
			dp[i][i] = 1;
		}
		int res = -1;
		for (int i = 0; i <= 30; i++) {
			for (int k = 0; k < n; k++) {
				bool flag = true;
				for (int j = 0; j < n; j++) {
					if (dp[k][j] == 0) {
						flag = false;
						break;
					}
				}
				if (flag) {
					res = i;
					break;
				}
			}
			if (res != -1) {
				break;
			}
			if (v[i].size() > 1) {
				vector<int> su(n);
				for (auto m : v[i]) {
					for (int j = 0; j < n; j++) {
						su[j] = max(su[j], dp[m][j]);
					}
				}
				for (auto m : v[i]) {
					for (int j = 0; j < n; j++) {
						dp[m][j] = max(dp[m][j], su[j]);
					}
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}