#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, p, r[50], d[50][50]; bool a[50][30];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &r[i]);
			for (int j = 0; j < 30; j++) {
				a[i][j] = false;
			}
			for (int j = 0; j < r[i]; j++) {
				scanf("%d", &p); a[i][p - 1] = true;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = 9999999;
			}
		}
		for (int i = 0; i < n; i++) {
			queue<pair<int, int> > que; que.push(make_pair(0, i)); d[i][i] = 0;
			while (!que.empty()) {
				pair<int, int> state = que.front(); que.pop();
				int dist = -state.first;
				int node = state.second;
				for (int j = 0; j < n; j++) {
					for (int k = dist; k < 30; k++) {
						if (a[node][k] && a[j][k]) {
							if (d[i][j] > k) {
								d[i][j] = k; que.push(make_pair(-k, j));
							}
						}
					}
				}
			}
		}
		int ret = 9999999;
		for (int i = 0; i < n; i++) {
			int res = 0;
			for (int j = 0; j < n; j++) {
				res = max(res, d[j][i]);
			}
			ret = min(ret, res);
		}
		printf("%d\n", ret == 9999999 ? -1 : ret + 1);
	}
	return 0;
}