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

int main()
{
	int n, m, d;
	
	while (cin >> n, n) {
		vector<vector<int>> f(n, vector<int>(31, 0));
		vector<vector<long long>> dp(n, vector<long long>(31, 0));
		for (int i = 0; i < n; i++) {
			cin >> m;
			while (m--) {
				cin >> d;
				f[i][d] = 1;
			}
			dp[i][0] = 1L << i;
		}
		int res = -1;
		for (int i = 1; i < 31; i++) {
			for (int j = 0; j < n; j++) {
				if (!f[j][i]) {
					dp[j][i] = dp [j][i - 1];
					continue;
				}
				for (int k = 0; k < n; k++) {
					if (!f[k][i]) continue;
					dp[j][i] |= dp[k][i - 1];
				}
				if (dp[j][i] == (1L << n) - 1) {
					res = i;
					break;
				}
			}
			if (res != -1) break;
		}
		cout << res << endl;
	}
	
	return 0;
}