main(n,i,d,r){for(;scanf("%d",&n)*n;printf("%d \n",r)){int h[50][31]={0};long long m[50],a;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<=30;){a=0;for(i=n;i--;)a|=m[i]*h[i][d];for(i=n;i--;r=m[i]-(1LL<<n)+1?r:d)m[i]|=a*h[i][d];}}}