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

set<int> p[101];

int main() {
  int n, ans, m, pp;
  while(cin>>n, n) {
    ans = -1;
    for (int i=0; i<n; ++i) {
      p[i].clear();
      cin>>m;
      for (int j=0; j<m; ++j) {
        cin>>pp; p[i].insert(pp);
      }
    }

    set<int> target;
    cin>>m;
    for (int i=0; i<m; ++i) {
      cin>>pp; target.insert(pp);
    }

    for (int i=0; i<n; ++i) {
      bool ok = true;
      for (set<int>::iterator it = target.begin(); it != target.end(); ++it) {
        if (p[i].find(*it) == p[i].end()) ok = false;
      }
      if (ok) {
        if (ans == -1) ans = i+1;
        else ans = -2;
      }
    }

    if (ans < 0) ans = -1;
    cout<<ans<<endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
#include <map>
#include <list>
#include <cstdlib>

using namespace std;

typedef pair<int, int> P;

#define MAX 128

int main()
{
	while(1) {
		int n;
		set<int> know[MAX];
		bool leak[MAX];

		for(int i = 0; i < MAX; i++) {
			leak[i] = true;
		}
		
		scanf("%d", &n);
		if(!n) break;
		for(int i = 1; i <= n; i++) {
			int m;
			scanf("%d", &m);
			while(m--) {
				int p;
				scanf("%d", &p);
				know[i].insert(p);
			}
		}

		int k;
		scanf("%d", &k);
		while(k--) {
			int l;
			scanf("%d", &l);
			for(int i = 1; i <= n; i++) {
				if(!leak[i]) continue;
				set<int>::iterator it = know[i].find(l);
				if(it == know[i].end()) {
					leak[i] = false;
				}
			}
		}

		int ans = -1;
		for(int i = 1; i <= n; i++) {
			if(!leak[i]) continue;
			if(ans > 0) {
				ans = -1;
				break;
			}
			ans = i;
		}
		printf("%d\n", ans);
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <set>


using namespace std;

int main() {
	int length[100];
	int ary[100][100];

	while (true) {
		int N;
		scanf("%d", &N);
		if (N == 0)
			break;
		for (int i = 0; i < N; ++i) {
			scanf("%d", &length[i]);
			for (int j = 0; j < length[i]; ++j) {
				scanf("%d", &ary[i][j]);
			}
		}


		int K;
		scanf("%d", &K);
		
		int exposed[100];
		for (int i = 0; i < K; ++i) {
			int p;
			scanf("%d", &p);
			exposed[i] = p;
		}

		int prisoner = -1;
		for (int i = 0; i < N; ++i) {
			bool founded[100] = {};
			int j = 0;
			for (; j < K; ++j) {
				int k = 0;
				for (; k < length[i]; ++k) {
					if (exposed[j] == ary[i][k]) {
						founded[j] = true;
						break;
					}
				}

			}

			j = 0;
			for (; j < K; ++j) {
				if (!founded[j])
					break;
			}
			if (j == K) {
				if (prisoner > 0) {
					prisoner = -1;
					break;
				} else {
					prisoner = i+1;
				}
			}
				

		}

		printf("%d\n", prisoner);

	}
}

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

int main(){
  int N,M,K;

  while(1){
    vector<vector<int> > p(101,vector<int>(101,-1));
    vector<int> l(101,-1);

    cin>>N;
    if(N==0)break;    
    for(int i=0;i<N;i++){
      cin>>M;
      for(int j=0;j<M;j++) cin>>p[i][j];
    }
    
    cin>>K;
    for(int i=0;i<K;i++) cin>>l[i];

    int ans=-1;
    for(int i=0;i<N;i++){
      int count=0;
      for(int j=0;p[i][j]!=-1;j++){
	for(int k=0;l[k]!=-1;k++){
	  if(p[i][j]==l[k]) count++;
	}
      }
      if(count==K&&ans==-1) ans=i+1;
      else if(ans!=-1&&count==K){
	ans=-1;
	break;
      }
    }

    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    
    while (scanf("%d", &n) && n){
        bitset<128> p[128];
        bitset<128> q;
        
        for (int i = 0; i < n; i++){
            int m;
            scanf("%d", &m);
            p[i] = 0;
            for (int j = 0; j < m; j++){
                int x;
                scanf("%d", &x);
                p[i][x] = 1;
            }
        }
        int m;
        scanf("%d", &m);
        for (int j = 0; j < m; j++){
            int x;
            scanf("%d", &x);
            q[x] = 1;
        }
        
        int ret = -1;
        int cnt = 0;
        for (int i = 0; i < n; i++){
            if ((p[i] & q) == q){
                ret = i + 1;
                cnt++;
            }
        }
        
        printf("%d\n", cnt == 1 ? ret : -1);
    }
    
    return (0);
}

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

int main(){
    while(true){
        int n, m, k;
        int candidate[100];
        set<int> p[100];
        int ans=0;
        cin >> n;
        if(!n) break;
        for(int i=0;i<n;++i){
            candidate[i] = 1;
            cin >> m;
            for(int j=0;j<m;++j){
                int l;
                cin >> l;
                p[i].insert(l);
            }
        }
        cin >> k;
        for(int i=0;i<k;++i){
            int l;
            cin >> l;
            for(int j=0;j<n;++j){
                if(candidate[j]){
                    if(p[j].find(l)==p[j].end()){
                        candidate[j] = 0;
                    }
                }
            }
        }
        for(int i=0;i<n;++i){
            if(candidate[i] && ans == 0) ans = i+1;
            else if(candidate[i] && ans > 0){
                ans = -1;
                break;
            }
        }
        if(ans == 0) ans = -1;
        cout << ans << endl;
    }
}