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<cstdio>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main(void){
	
	int n,m;
	
	while(cin >> n,n){
		vector<int>v[101];
		for(int i=1;i<=n;i++){
			cin >> m;
			int a;
			for(int j=0;j<m;j++){
				cin >> a;
				v[i].push_back(a);
			}
		}
		int k;
		cin >> k;
		vector<int>l(k);
		for(int i=0;i<k;i++)cin >> l[i];
		
		int ans=0,id=0;
		for(int i=1;i<=n;i++){
			bool fg=true;
			for(int j=0;j<l.size();j++)
				if(v[i].size()>0 && !binary_search(v[i].begin(),v[i].end(),l[j]))fg=false;
			if(fg)ans++,id=i;
		}
		if(ans==1)cout << id << endl;
		else cout << -1 << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main()
{
  while(1){
    int N;
    cin >> N;
    if(N == 0) break;
    vector<int> info[N];
    REP(i,N){
      int M;
      cin >> M;
      REP(j,M){
        int x;
        cin >> x;
        info[i].push_back(x);
      }
    }
    int K;
    cin >> K;
    int leak[K];
    REP(i,K)
      cin >> leak[i];
    int c;
    int ans = -1;
    bool flag = true;
    REP(i,N){
      c = 0;
      REP(j,K){
        if(find(info[i].begin(), info[i].end(), leak[j]) != info[i].end())
          c++;
      }
      if(c == K){
        if(ans == -1){
          ans = i + 1;
        }else{
          flag = false;
          cout << "-1" << endl;
          break;
        }
      }
    }
    if(flag)
      cout << ans << endl;
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <set>

using namespace std;

inline int getInt() { int s; scanf("%d", &s); return s; }

// bad knowhow
#define ALL(c) (c).begin(), (c).end()
#define REP(i,n) for(long long i=0;i<(long long)n;++i)
#define MAX_SIZE 100

set<int> g_p[MAX_SIZE];
set<int> g_leak;

int main() {
	//freopen("Text.txt", "r", stdin);
	while (true) {
		REP(i, MAX_SIZE) g_p[i].clear();
		g_leak.clear();

		const int n = getInt();
		if (n==0) break;
		
		REP(i, n) {
			const int m = getInt();
			REP(j, m) g_p[i].insert(getInt()-1);
		}

		const int k = getInt();
		REP(i, k) g_leak.insert(getInt()-1);

		vector<int> suspect;
		REP(i,n) {
			vector<int> is;
			if (includes(ALL(g_leak), ALL(g_p[i]))) suspect.push_back(i);
		}

		cout << ((suspect.size()==1) ? suspect[0] + 1 : -1) << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ALL(a) a.begin(),a.end()
int main(){
  int n;
  while( cin >> n , n ){
    vector < int > p[n],L;
    for(int i = 0, q, d ; i < n && cin >> q ; sort(ALL(p[i])), i++ ){
      while(q--) cin >> d, p[i].push_back(--d);
    }
    int K, l, ans = -1, flg = -1;
    cin >> K;
    while(K--) cin >> l, L.push_back(--l);
    sort(ALL(L));
    for(int i = 0 ; i < n && flg<=0 ; i++ ){
      if(includes(ALL(p[i]),ALL(L))) ans = i + 1, flg++;
    }
    cout << (flg ? -1 : ans) << endl;
  }
}

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

using namespace std;

int main(void){
//	FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1) {
		int N, M, tmp;
		cin >> N;
		if( N == 0 ) break;

		vector< vector< int > >data;
		vector< int > plist;
		for(int i = 0; i <= N; i++) plist.push_back(0);

		//データ入力
		for(int i = 0; i < N; i++) {
			cin >> M;
			vector<int> newdata;
			for(int j = 0; j < M; j++) {
				cin >> tmp;
				plist.at( tmp ) ++;
				newdata.push_back( tmp );
			}
			data.push_back( newdata );
		}

		//流出情報取得
		int K;
		vector<int> leak;
		cin >> K;
		for(int i = 0; i < K; i++) {
			int tmp;
			cin >> tmp;
			if( plist.at(tmp) == 1 )
				leak.push_back( tmp );
		}

		//leakは、対応するインデックスの個人情報を1人しか知らない流出番号
		vector<int> suspect;
		for(int i = 0; i <= N; i++)
			suspect.push_back( 0 );

		for(int i = 0; i < data.size(); i++) {
			for(int j = 0; j < data.at(i).size(); j++) {
				for(int k = 0; k < leak.size(); k++) {
					if( data.at( i ).at( j ) == leak.at( k ) ) {
						suspect.at( i + 1 ) ++;
						break;
					}
				}
			}
		}

		vector<int> ans;
		for(int i = 0; i < suspect.size(); i++)
			if( suspect.at(i) > 0 ) ans.push_back( i );

		if( ans.size() == 1 ) {
			cout << ans.at( 0 ) << endl;
		} else {
			cout << -1 << endl;
		}

	}

//	while(1){}

	return 0;
}

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

using namespace std;

int main(void) {
	int N,K;
	cin >> N;
	while (N != 0) {
		vector<int> M(N);
		vector< vector<int> > data(N, vector<int>(100,101));
		for (int i = 0; i < N; ++i) {
			cin >> M[i];
			for (int j = 0; j < M[i]; ++j) {
				cin >> data[i][j];
			}
			sort(data[i].begin(),data[i].end());
		}
		cin >> K;
		vector<int> l(K);
		for (int i = 0; i < K; ++i) {
			cin >> l[i];
		}

		int res = -1;
		int ind = 0;
		bool seq = true;
		for (int i = 0; i < N && res != 0; ++i) {
			ind = 0;
			seq = true;
			for (int j = 0; j < K && seq; ++j) {
				if (data[i][ind] < l[j]) {
					while (data[i][ind] < l[j]) {
						++ind;
					}
				}
				if (data[i][ind] == l[j]) {
					++ind;
					if (j == K - 1) {
						//cout << i + 1 << " ";
						if (res < 0) {
							res = i + 1;
						}
						else {
							res = 0;
						}
					}
				}
				else {
					seq = false;
				}
			}
		}

		if (res > 0) {
			cout << res << endl;
		}
		else {
			cout << -1 << endl;
		}

		cin >> N;
	}
	return 0;
}