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>

using namespace std;

bool search(int n,int k,vector<vector<int> >&list,vector<int>&a){
    bool flag;
    for(int i=0;i<k;i++){
        flag=false;
        for(int j=1;j<=list[n][0];j++){
            if(list[n][j]==a[i]){
                flag=true;
                break;
            }
        }
        if(!flag)return false;
    }
    return true;
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        vector<vector<int> >list(n,vector<int>(n+1,0));
        for(int i=0;i<n;i++){
            cin >> list[i][0];
            for(int j=1;j<=list[i][0];j++){
                cin >> list[i][j];
            }
        }
        int k;
        cin >>k;
        vector<int> a(k,0);
        for(int i=0;i<k;i++){
            cin >> a[i];
            }
        bool flag=false;
        int ans=-1;
        for(int i=0;i<n;i++){
            if(search(i,k,list,a)){
                if(ans!=-1){
                    ans=-1;
                    break;
                }
                else ans=i+1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, a[128][128], b[128];

void readA(int *a) {
    rep (i, n) a[i] = 0;
    int m;
    scanf("%d", &m);
    rep (i, m) {
        int x;
        scanf("%d", &x);
        a[x-1] = 1;
    }
}

bool can(int k) {
    rep (i, n) if (b[i] && !a[k][i]) return false;
    return true;
}

int main() {
    for (;;) {
        scanf("%d", &n);
        if (n == 0) return 0;
        rep (i, n) readA(a[i]);
        readA(b);
        int c = 0;
        rep (i, n) if (can(i)) c++;
        if (c != 1) printf("%d\n", -1);
        else rep (i, n) if (can(i)) printf("%d\n", i+1);
    }
}

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

int main(){
  int i,j,k,n,m,data[101][101],temp,cnt,cnt_num,result[101];
  while(1){
    for(i = 1; i < 101; i++){
      for(j = 1; j < 101; j++){
	data[i][j]=0;
	result[j]=0;
      }
    }
    
    cnt=0,cnt_num=0;
    cin >> n;
    if(n==0)break;
    for(i = 1; i <= n; i++){
      cin >> m;
      for(j = 1; j <=m; j++){
	cin >> data[i][j];
      }
    }

    cin >> k;
    for(i = 1; i <= k; i++){
      cin >> result[i];
    }

    for(i = 1; i <= n; i++){
      //cout << "i " << i << endl;
      cnt=0;
      for(j = 1; j <= 101; j++){
	for(int l =1; l <= k; l++){
	if(data[i][j]==0 || result[l]==0)continue;
	if(data[i][j]==result[l])cnt++;
	//	cout << data[i][j] << " " << result[l] << endl;
	//	cout << "cnt" << cnt << endl;
	  if(cnt==k){
	  cnt_num++;
	  //	  cout << "cnt_num" <<  cnt_num <<endl;
	  temp = i;
	  }
	}
      }
    }

    if(cnt_num==1){
      cout << temp << endl;
    }else{ 
      cout << -1 << endl;
    }
    
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

int main() {
	int n;
	while(cin >> n, n) {
		int f[101][101] = {};
		FOR(i, 1, n+1) {
			int m; cin >> m;
			FOR(j, 1, m+1)
				cin >> f[i][j];
		}
		int k; cin >> k;
		int l[k], cnt, ans = 0;
		REP(i, k)
			cin >> l[i];
		FOR(i, 1, n+1) {
			cnt = 0;
			FOR(j, 1, n+1) {
				if(f[i][j] == l[cnt]) {
					cnt++; 
				}
				if(cnt == k) {
//					cout << cnt << ' ' << k << ' ' << " cnt" << endl;
					if(!ans) ans = i;
					else ans = -1;
					break;
				}
			}
		}
		if(ans < 1) ans = -1;
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        vector<vector<int>> d(n);
        for (int i = 0; i < n; ++i) {
            int m,t;
            cin>>m;
            for (int j = 0; j < m; ++j) {
                cin>>t;
                d[i].emplace_back(t);
            }
            sort(d[i].begin(),d[i].end());
        }
        int kn;
        cin>>kn;
        vector<int> k(kn);
        for (int i = 0; i < kn; ++i) {
            cin>>k[i];
        }
        sort(k.begin(),k.end());
        vector<int> susp;
        for (int i = 0; i < n; ++i) {
            int di=0,ki=0;
            int ands=0;
            while(di<d[i].size()&&ki<k.size()){
                if(d[i][di]==k[ki]){
                    ++ands;
                    ++di;
                    ++ki;
                }
                else if(d[i][di]<k[ki])++di;
                else ++ki;
            }
            if(ands==kn)susp.emplace_back(i+1);
        }
        if(susp.size()==1)cout<<susp[0]<<endl;
        else cout<<-1<<endl;
    }
    return 0;
}