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<algorithm>
using namespace std;

int main(){
    while(1){
        int N; cin >> N;
        if(N == 0) break;
        vector<vector<int> > info(N, vector<int>(0));
    
        for(int i = 0; i < N; i++){
            int M; cin >> M;
            for(int j = 0; j < M; j++){
                int p; cin >> p;
                info[i].push_back(p);
            }
        }
    
        int K; cin >> K;
        vector<int> leak(K);
        for(int i = 0; i < K; i++){
            cin >> leak[i];
        }
   
        vector<int> ans;
        for(int i = 0; i < N; i++){
            int cnt = 0;
            for(int j = 0; j < K; j++){
                auto isFind = find(info[i].begin(), info[i].end(), leak[j]);
                if(isFind != info[i].end()){
                    cnt++;
                }
            }
            if(cnt == K){
                ans.push_back(i+1);
            }
        }
        
        if(ans.size() == 1) cout << ans[0] << endl;
        else cout << -1 << endl;
    }
    
    return 0;
}

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

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

using namespace std;
typedef long long ll;

int main()
{
    int n;
    while(cin >> n && n ) {

        vector<vector<int> > v(n);
        rep(i,n) {
            int m,p;
            cin >> m;
            rep(j,m) {
                cin >> p;
                v[i].push_back(p);
            }
        }

        rep(i,n) {
            sort(v[i].begin(),v[i].end());
        }

        int k;
        cin >> k;

        vector<int> l(k);
        rep(i,k) cin >> l[i];

        int cnt = 0;
        int ans = 0;

        rep(i,n) {
            bool flag = true;
            rep(j,k){
                if(!binary_search(v[i].begin(),v[i].end(),l[j])) {
                    flag = false;
                }
            }

            if(flag) {
                cnt++;
                ans = i;
            }
        }


        if(cnt == 1) cout << ans+1 << endl;
        else cout << -1 << endl;
    }

    return 0;
}

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

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

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		vector<int> know[100];
		rep(i,n){
			int m; scanf("%d",&m);
			rep(j,m){
				int a; scanf("%d",&a); a--;
				know[i].push_back(a);
			}
		}

		int k; scanf("%d",&k);
		vector<int> leak(k);
		rep(i,k) scanf("%d",&leak[i]), leak[i]--;

		int ans=-1;
		rep(i,n){
			bool ok=false;
			rep(j,k) if(count(know[i].begin(),know[i].end(),leak[j])==0) ok=true;
			if(!ok){
				if(ans==-1) ans=i;
				else        ans=-2;
			}
		}
		printf("%d\n",ans>=0?ans+1:-1);
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int N;

bool samecmp(long long int N,long long int memo[],long long int memo2[]){
	for(int i=1;i<=N;i++){
		if(memo[i]==0&&memo2[i]==1){
			return false;
		}
	}
	return true;
}
int main() {
	
	cout << fixed << setprecision(18);
	cin>>N;
	while(N!=0){
		long long int M,p,memo[105][105]={};
		for(int i=1;i<=N;i++){
			cin>>M;
			for(int j=1;j<=M;j++){
				cin>>p;
				memo[i][p]=1;
			}
		}
		long long int K,memo2[105]={};
		cin>>K;
		for(int j=1;j<=K;j++){
			cin>>p;
			memo2[p]=1;
		}
		long long int Num=0,ID;
		for(int i=1;i<=N;i++){
			if(samecmp(N,memo[i],memo2)){Num++;ID=i;}
		}
		if(Num==1){cout<<ID<<endl;}
		else {cout<<-1<<endl;}
		cin>>N;
	}

}

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

int main(){
  int cnt,ans,m,n,i,j,k,info[101][101],hantei[101];
  while(1){
    for(i = 1; i < 101; i++){
      hantei[i] = 0;
      for(j = 1; j < 101; j++){
      info[i][j] = 0;
      }
    }
    cin >> n;
    if(n==0)break;
    for(i = 1; i <= n; i++){
      cin >> m;
      for(j = 1; j <= m; j++){
	int num;
	cin >> num;
	info[i][num] = 1;
      }
    }
    cin >> k;
    for(i = 1; i <= k; i++){
      int num2;
      cin >> num2;
      hantei[num2] = 1;
    }
    int total = 0;
    for(i = 1; i < 101; i++){
      cnt = 0;
      for(j = 1; j < 101; j++){
	if(hantei[j]==info[i][j] && hantei[j]==1)cnt++;
      }
      if(cnt==k){
	ans = i;
	total++;
      }
    }
    
  if(total==1)cout << ans << endl;
  else cout << -1 << endl;
  }
  return 0;
}