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<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define onen(i,n) for(int i=1;i<n+1;i++)

const int MAXN = 101, MAXK = 101;

int n,m,k,t,p,l;
bool joho[MAXN][MAXN];
bool still[MAXN];

int main()
{
    while(cin >> n && n)
    {
        memset(still, true, sizeof(still));
        memset(joho, false, sizeof(joho));
        int ans = -1;
        int num = 0;
        //for(int i=1;i<=n;i++)
        onen(i,n)
        {
            cin >> t;
            rep(j,t)
            {
                cin >> p;
                joho[i][p] = true;
            }
        }

        cin >> k;
        rep(j,k)
        {
            cin >> l;
            onen(i,n) still[i] = still[i] & joho[i][l];
        }

        onen(i,n)if(still[i])
        {
            ans = i;
            num++;
        }
        if(num>=2 || num == 0) {cout << -1 << endl; continue;}
        else cout << ans << endl;

    }

    return 0;
}

C++: #include <iostream>
#include <set>

#define rep2(i, b, n) for(int i=b; i < n; ++i)
#define rep(i, n) rep2(i, 0, n)

using namespace std;

int main( void )
{
	int n;
	set<int> info[100];
	while(cin >> n, n) {
		rep(i, n) {
			int m; cin >> m;
			info[i].clear();
			rep(j, m) {
				int p; cin >> p;
				info[i].insert(p);
			}
		}
		int k, *kk, ans, count = 0;
		kk = new int[n];
		cin >> k;
		rep(i, k) cin >> kk[i];
		rep(i, n) {
			bool hit = true;
			rep(j, k) {
				hit &= (bool)info[i].count(kk[j]);
			}
			if(hit) {
				ans = i+1;
				count++;
			}
		}
		if(count == 1)
			cout << ans << endl;
		else
			cout << -1 << endl;
	}

	return 0;
}

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

int main(int argc, char *argv[])
{
    int n, m, p, k, l;
    while (cin >> n, n) {
        vector<vector<int> > data(n);
        vector<int> leaked;
        vector<int> suspect;
        vector<int>::iterator itr;
        for (int i = 0; i < n; ++i) {
            cin >> m;
            for (int j = 0; j < m; ++j) {
                cin >> p;
                data[i].push_back(p);
            }
        }
        cin >> k;
        for (int i = 0; i < k; ++i) {
            cin >> l;
            leaked.push_back(l);
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < k; ++j) {
                itr = find(data[i].begin(), data[i].end(), leaked[j]);
                if (itr == data[i].end())
                    break;
            }
            if (itr != data[i].end())
                suspect.push_back(i + 1);
        }
        if (suspect.size() == 1)
            cout << suspect[0] << endl;
        else
            cout << -1 << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void){
	int member[100][100], leak, n, m, i, j, x, count, res, flag;
	scanf("%d",&n);
	while(n){
		memset(member,0,sizeof(member));
		for(i = 0;i < n;i++){
			scanf("%d",&m);
			for(j = 0;j < m;j++){
				scanf("%d",&x);
				member[i][x - 1] = 1;
			}
		}
		scanf("%d",&m);
		res = -1;
		flag = 0;
		for(i = 0;i < m;i++){
			scanf("%d",&leak);
			count = 0;
			for(j = 0;j < n;j++)
				if(member[j][leak - 1]) count++;
			for(j = 0;j < n;j++)
				if(member[j][leak - 1]) break;
			if(!flag && count == 1){
				res = j + 1;
				flag = 1;
			}else if(flag && count == 1 && res != j + 1)
				res = -1;
		}
		printf("%d\n",res);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

bool kw[101][101];
bool sp[101];

signed main() {
	int n, m, p, k, l;
	while (cin >> n && n) {
		rep(i, 0, n) rep(j, 0, n) kw[i][j] = false;
		rep(i, 0, n) sp[i] = true;
		rep(i, 0, n) {
			cin >> m;
			rep(j, 0, m) {
				cin >> p;
				kw[i][p - 1] = true;
			}
		}
		cin >> k;
		vi lost(k);
		rep(i, 0, k) {
			cin >> l;
			lost[i] = l - 1;
		}
		rep(i, 0, k) {
			rep(j, 0, n) {
				if (sp[j]) {
					if (kw[j][lost[i]] == false) sp[j] = false;
				}
			}
		}
		int ans = -1;
		rep(i, 0, n) {
			if (sp[i] && ans == -1) ans = i + 1;
			else if (sp[i] && ans != -1) ans = -1;
		}
		cout << ans << endl;
	}
}

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

int main(){

int N;
while(1){
cin>>N;
int M;
bool n[101][101]={};
for(int i=1;i<=N;i++){
cin>>M;
for(int j=0;j<M;j++)
{int x;cin>>x;n[i][x]=true;}
}

bool R[101]={};
cin>>M;
for(int i=0;i<M;i++)
{int x;cin>>x;R[x]=true;}
int c=0,k=0;

for(int i=1;i<=N;i++){bool f=true;
for(int j=1;j<=N;j++)
{
if(n[i][j]!=R[j]&&R[j]==true)f=false;
}
if(f==true){c++;k=i;}
}

if(c==1)cout<<k<<endl;
else{cout<<"-1"<<endl;}
}
return 0;
}