Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()

	for {
		N := io.NextInt()
		if N == 0 {
			break
		}
		set := make([]map[int]struct{}, N)
		for i := 0; i < N; i++ {
			set[i] = make(map[int]struct{})
			M := io.NextInt()
			for j := 0; j < M; j++ {
				p := io.NextInt()
				set[i][p] = struct{}{}
			}
		}
		K := io.NextInt()
		l := make([]int, K)
		for i := 0; i < K; i++ {
			l[i] = io.NextInt()
		}

		ans := 0
	FOR_OUTER:
		for i := 0; i < N; i++ {
			for j := 0; j < K; j++ {
				if _, f := set[i][l[j]]; f == false {
					continue FOR_OUTER
				}
			}
			switch ans {
			case 0:
				ans = i + 1
			default:
				ans = -1
			}
		}
		if ans > 0 {
			io.Println(ans)
		} else {
			io.Println(-1)
		}
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: //include
//------------------------------------------
#include <bits/stdc++.h> // only for GCC

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

//repetition
//------------------------------------------
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

//clear memory
// ------------------------------------------
#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
   int n,m;
   while(cin >> n && n){
      int m;
      vvi b;
      int ans=-1;
      bool c=true;
      
      rep(i,n+1){
         cin >> m;         
         vi a(m);
         rep(i,m) cin >> a[i];
         sort(all(a));
         b.pb(a);
      }
      rep(i,n){
         if(b[i].size()>=b[n].size()){
            rep(j,b[n].size()){
               if(count(all(b[i]),b[n][j])==0) break;
               else if(j==b[n].size()-1){
                  if(ans==-1) ans=i+1;
                  else{
                     c=false;
                     break;
                  }
               }
            }
         }
      }
      if(c!=false) cout << ans << endl;
      else cout << -1 << endl;
   }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main(void){
	
	int n,m;
	
	while(cin >> n,n){
		vector<int>v[101];
		for(int i=1;i<=n;i++){
			cin >> m;
			int a;
			for(int j=0;j<m;j++){
				cin >> a;
				v[i].push_back(a);
			}
		}
		int k;
		cin >> k;
		vector<int>l(k);
		for(int i=0;i<k;i++)cin >> l[i];
		
		vector<int>ans;
		for(int i=1;i<=n;i++){
			bool fg=true;
			for(int j=0;j<l.size();j++)
				if(!binary_search(v[i].begin(),v[i].end(),l[j]))fg=false;
			if(fg)ans.push_back(i);
		}
		if(ans.size()==1)cout << ans[0] << endl;
		else cout << -1 << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;
int sirabe(int);
int sagasu(int,int);

int n,m[101][101],k[101],fg,ans;

int main(){
	
	cin>>n;
	
	while(n!=0){
		
		for(int lop=0;lop<101;lop++){
			k[lop]=0;
			for(int lop2=0;lop2<101;lop2++){
				m[lop][lop2]=0;
			}
		}
		fg=0;
		ans=0;
		
		for(int lop=0;lop<n;lop++){
			cin>>m[lop][0];
			for(int lop2=1;lop2<m[lop][0]+1;lop2++){
				cin>>m[lop][lop2];
			}
		}
		
		cin>>k[0];
		for(int lop=1;lop<k[0]+1;lop++){
			cin>>k[lop];
		}
		
		/*cout<<"aaaaa"<<endl;
		for(int lop=0;lop<n;lop++){
			for(int lop2=0;lop2<m[lop][0]+1;lop2++){
				cout<<m[lop][lop2]<<' ';
			}
			cout<<endl;
		}
		
		for(int lop=1;lop<k[0]+1;lop++){
			cout<<k[lop]<<' ';
		}
		cout<<endl;*/
		
		for(int lop=0;lop<n;lop++){
			if(sirabe(lop)==1){
				if(fg==0){
					fg=1;
				}else{
					fg=2;
					break;
				}
			}
		}
		
		if(fg==0 || fg==2){
			cout<<-1<<endl;
		}else{
			cout<<ans+1<<endl;
		}
		
		
		cin>>n;
	}
	
	return 0;
}

int sirabe(int hito){
	
	/*for(int lop=1;lop<m[hito][0]+1;lop++){
		if(sagasu(m[hito][lop])==0){
			return 0;
		}
	}*/
	for(int lop3=1;lop3<k[0]+1;lop3++){
		
		if(sagasu(k[lop3],hito)==0){
			return 0;
		}
	}
	
	ans=hito;
	return 1;
}
	
int sagasu(int num,int hito2){
	
	/*for(int lop3=1;lop3<k[0]+1;lop3++){
		
		if(k[lop3]==num){
			
			return 1;
		}
		
	}*/
	for(int lop=1;lop<m[hito2][0]+1;lop++){
		if(num==m[hito2][lop]){
			return 1;
		}
	}
	
	return 0;
}