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 <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>

using namespace std;

// typedef
typedef long long ll;

// container util
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(c) int((c).size())
#define EACH(i,c) for(auto (i)=(c).begin(); (i)!=(c).end(); ++(i))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))

// repetition
#define FOR(i,m,n) for(ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for(ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)

// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl

// constant
const double    EPS     = 1e-10;
const int       INFTY   = (1<<21);
const ll        MOD     = (ll) 1e9+7;

// clear memory
#define CLR(a) memset((a),0,sizeof(a))

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << " " << __FILE__ << endl;

int solve(int n) {
    vector<unordered_set<int>> personals;
    unordered_set<int> out;
    REP(i, n) {
        int m; cin >> m;
        unordered_set<int> person;
        REP(j, m) {
            int e;
            cin >> e;
            person.emplace(e);
        }
        personals.push_back(person);
    }
    int m; cin >> m;
    REP(j, m) {
        int e;
        cin >> e;
        out.emplace(e);
    }
    int x = 0;
    int ret = -1;
    REP(i, n) {
        bool is_subset = true;
        EACH(j, out) is_subset &= EXIST(personals[i], *j);
        if(is_subset) {
            x++;
            if(x == 1) ret = i + 1;
            else ret = -1;
        }
    }
    return ret;
}

int main() {
    while(true) {
        int n; cin >> n;
        if(n == 0) break;
        cout << solve(n) << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;

typedef struct{
  int n;
  int list[101];
}Data;

int N,cnt,criminal;
Data data[101],leak_data;

void search(){

  int cnt2;
  
  for(int i=1 ; i <= N ; i++){
    cnt2=0;
    for(int j=1 ; j <= leak_data.n ; j++){
      for(int k=1 ; k <= data[i].n ; k++){
	if(leak_data.list[j] == data[i].list[k])cnt2++;
      }
    }
    if(cnt2 == leak_data.n){
      criminal=i;
      cnt++;
    }
  }
  
}
int main(){
  
  while(1){
    
    cin >>N;
    if(N == 0)break;

    cnt=0;
    
    for(int i=1 ; i <= N ; i++){
      cin >>data[i].n;
      for(int j=1 ; j <= data[i].n ; j++){
	cin >>data[i].list[j];
      }
    }
    
    cin >>leak_data.n;
    for(int i=1 ; i <= leak_data.n ; i++){
      cin >>leak_data.list[i];
    }
    
    search();
    
    if(cnt != 1){
      cout <<"-1"<<endl;
    }else{
      cout <<criminal<<endl;
    }
    
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int n;

    while(cin >> n,n){
        vector<int> m(n);
        int set[100][100]={{}};
        for(int i=0;i<n;i++){
            cin >> m[i];
            for(int j=0;j<m[i];j++){
                int p;
                cin >> p;
                set[i][p]=1;
            }
        }

        int k;
        cin >> k;
        vector<int> l(k);
        for(int i=0;i<k;i++){
            cin >> l[i];
        }

        int frg=0;
        for(int i=0;i<n;i++){
            int sfrg=1;
            for(int j=0;j<k;j++){
                sfrg*=set[i][l[j]];
            }
            if(sfrg==1){
                if(frg==0)frg=i+1;
                else frg=-1;
            }
        }
        if(frg>0)cout << frg << endl;
        else cout << -1 << endl;
    }
    return 0;
}

C++: #include<iostream>
#define N 100
using namespace std;

int main(){
  while(1){
  int n,m,pr;
  int p[N]={};
  cin>>n;
  if(n==0) break;
  for(int i=1;i<=n;i++){
    cin>>m;
    for(int j=0;j<m;j++){
      cin>>pr;
      if(p[pr]==0)
    p[pr]=i;
      else p[pr]=-1;

    }
  }
    cin>>m;
    int ans=0,f=0;
    for(int i=0;i<m;i++){
      cin>>pr;
          if(p[pr]>0 && f==0 &&(ans==0 || ans==p[pr])) ans=p[pr];
        }
     if(ans==0) ans=-1;
    cout<<ans<<endl;
  }
  return 0;

}

C++: #include<iostream>
using namespace std;

int main()
{
	int n;
	while(cin>>n,n)
	{
		int p[101][101];
		for(int i=1;i<=n;i++)
		{
			cin>>p[i][0];
			for(int j=1;j<=p[i][0];j++) cin>>p[i][j];
		}
		int num;
		int k[100];
		cin>>num;
		for(int i=0;i<num;i++) cin>>k[i];

		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if(p[i][0]<num) continue;
			int cnt=0;
			for(int j=0;j<num;j++)
			{
				for(int l=1;l<=p[i][0];l++)
				{
					if(k[j]==p[i][l]) {cnt++; break;}
				}
			}
			if(cnt==num)
			{
				if(!ans) ans=i;
				else ans=-1;
			}
		}
		if(ans==0) ans=-1;
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>


using namespace std;

bool t[101][101];
int n,k;

int solve()
{
	for (int i = 0; i < n; i++){
		int m; cin>>m;
		t[i][i] = true;
		for (int j = 0; j < m; j++){
			int x; cin>>x;
			t[i][x-1] = true;
		}
	}

	cin>>k;
	vector<int> l(k);
	for (int i = 0; i < k; i++){
		cin>>l[i];  l[i]--;
	}

	int ans = -1;

	for (int i = 0; i < n; i++){
		int j = 0;
		for (; j < k; j++){
			if(!t[i][l[j]]) break; 
		}
		if(j == k){
			if(ans == -1) {
				ans = i + 1;
			} else {return -1;}
		}
	}

	return ans;
}

int main(){
	while(cin >> n,n){
		memset(t,0,sizeof(t));
		int ans = solve();
		cout << ans << endl;
	}
	return 0;
}