main(n,i,d,r){for(;scanf("%d",&n)*n;printf("%d\n",r)){int h[50][32]={0};long long m[50],a=0,b;for(i=n;i--;m[i]=1LL<<i)for(scanf("%d",&r);r--;h[i][d]=1)scanf("%d",&d);for(r=d=-1;!~r&&++d<32;a=b)for(b=0,i=n;i--;b|=m[i]*h[i][d+1])r=(m[i]|=a*h[i][d])-(1LL<<n)+1?r:d;}}