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 <stdio.h>
#include <string.h>

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

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n;
	while (scanf("%d", &n), n) {
		int E[100]{};
		rep(i, n) {
			int m; scanf("%d", &m);
			rep(j, m) {
				int p; scanf("%d", &p);
				E[--p] |= 1 << i;
			}
		}
		int k; scanf("%d", &k);
		int cnt = (1 << n) - 1;
		rep(i, k) {
			int l; scanf("%d", &l);
			cnt &= E[--l];
		}
		int ans = -1;
		rep(i, n) {
			if ((cnt >> i) & 1) {
				if (~ans) {
					ans = -1;
					break;
				}
				else ans = i + 1;
			}
		}
		printf("%d\n", ans);
	}
}

C++: #include <stdio.h>

int main(){
  
  int mm,kk,n;
  int m[105][105];
  
  int k[105];
  int i,j,rin,ans1,ans2,p,q;
  
  //  scanf("%d",&n);
  p=0;  q=0;
  while(1){  
    p++;
    ans1=0;
    for(i=0;i<105;i++){
      for(j=0;j<105;j++){
	m[i][j]=0;
      }
    }
    
    for(i=0;i<105;i++)
      k[i]=0;

    ans1=0;//初期化
    scanf("%d",&n);
    if(n==0){
      
      return 0;
    }//終了
    
    
  
    for(i=1;i<n+1;i++){
      scanf("%d",&mm);
  
      for(j=1;j<mm+1;j++){
	scanf("%d",&rin);

	m[i][rin]=1;
      }
    }
  
    scanf("%d",&rin);
    kk=rin;
    for(i=1;i<kk+1;i++){
      scanf("%d",&rin);
      k[rin]=1;}
    
    for(i=1;i<n+1;i++){
      for(j=1;m[i][j]>=k[j]&&j<n+1;j++);
  
      if(j==n+1)
	{  /*printf("--------\n");
	  for(j=1;j<n+1;j++) printf("%d ",m[i][j]);
	  printf("\n");
	  for(j=1;j<n+1;j++) printf("%d ",k[j]);
	  printf("\n--------\n");*/
	  ans1++;
	  ans2=i;
	}
    }

    /* for(i=1;i<n+1;i++){
        printf("\n");
      for(j=1;j<n+1;j++)
		printf("  %d",m[i][j]);
		}*/
    if(ans1==1) printf("%d\n",ans2);
      else printf("-1\n");
    
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
string IntToString(int);
int StringToInt(string);
int main(){
  while(1){
    int n;
    cin >> n;
    if(n == 0)break;
    vector<int> M(n);
    vector<bitset<101> > P(n,bitset<101>(0));
    for(int i = 0;i < n;i++){
      cin >> M[i];
      for(int j = 0;j < M[i];j++){
	int tmp;
	cin >> tmp;
	bitset<101> tmp_bit = (1 << (tmp-1));
	P[i] = (P[i] | tmp_bit);
      }
    }
    int more_n;
    cin >> more_n;
    bitset<101> more(0);
    for(int i = 0;i < more_n;i++){
      int tmp;
      cin >> tmp;
      bitset<101> tmp_bit = (1 << (tmp-1));
      more = (more | tmp_bit);
    }
    int flag = 0;
    int ans;
    for(int i = 0;i < n;i++){
      if((P[i] & more) == more){
	ans = i+1;
	flag++;
      }
    }
    if(flag == 1)cout << ans << endl;
    else cout << "-1" << endl;
    
  }
  return 0;   
}
string IntToString(int number){
  stringstream ss;
  ss << number;
  return ss.str();
}
int StringToInt(string number){
  stringstream ss;
  ss << number;
  int numInt;
  ss >> numInt;
  return numInt;
  
}

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

int main(){
    int N;
    while(cin>>N){
        if(N == 0) break;
        int M[110][110] = {-1};
        
        for(int i=0; i<N; i++){
            int m;
            cin>>m;
            for(int j=0; j<m; j++){
                cin>>M[i][j];
            }
        }

        int K;
        cin>>K;
        vector<int> L(K);
        for(int i=0; i<K; i++) cin>>L[i];

        vector<int> cnt(N,0);
        bool flag = true;
        bool found = false;
        int ans;

        for(int i=0; i<K; i++){
            for(int j=0; j<N; j++){
                for(int k=0; k<110; k++){
                    if(M[j][k] == -1) break;
                    if(L[i] == M[j][k]){
                        cnt[j]++;
                    }                           
                }
            }
        }

        for(int i=0; i<N; i++){
            if(cnt[i] == K){
                if(found) flag = false;
                if(!found){
                    ans = i+1;
                    found = true;
                }
            }
        }

        if(!found || !flag) ans = -1;

        cout<<ans<<endl;
    }

    return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	int m,p;
	int k,l;

	while(1){
		cin>>n;
		if(n==0) break;

		map<int,set<int> > mp;
		map<int,set<int> >::iterator it;
		
		for(int i1=0;i1<n;i1++){
			cin>>m;
			set<int> s;
			for(int i2=0;i2<m;i2++){
				cin>>p;
				s.insert(p);
			}
			mp[i1]=s;
		}
		cin>>k;
		for(int i1=0;i1<k;i1++){
			cin>>l;

			for(it=mp.begin();it!=mp.end();it++){
				if((*it).second.find(l)==(*it).second.end()) {
					mp.erase(it);
					
				}
			}
		}


		if(mp.size()==1) {
			it=mp.begin();
			cout<<(*it).first+1<<endl;
		}
		else cout<<-1<<endl;

	}
	return 0;
}