// AOJ 2011: Gather the Maps!
// 2017.11.1 bal4u@uu

#include <stdio.h>
#include <string.h>

long long f[32];

char buf[100], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, w, i, ans;
	long long mask;

	while (fgets(p=buf, 10, stdin) && *buf != '0') {
		n = getint();
		memset(f, 0, sizeof(f));
		mask = (1LL << n) - 1;
		ans = 0;
		for (i = 0; i < n; i++) {
			fgets(p=buf, 100, stdin);
			w = getint(), p++;
			if (!w) ans = -1;
			if (!ans) while (w-- > 0) f[getint()] |= 1LL << i, p++;
		}
		if (!ans) {
			for (ans = 1; ans <= 30; ans++) {
				f[ans] |= f[ans-1];
				if (f[ans] == mask) break;
			}
			if (ans > 30) ans = -1;
		}
		printf("%d\n", ans);
	}
	return 0;
}