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 <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

bool subset(vector<int> &a, vector<int> &b)
{
	if (a.size() > b.size()) return false;
	rep(i, a.size()) 
		if (find(ALL(b), a[i]) == b.end())
			return false;
	return true;
}

int main(void)
{
	int n;
	while (cin >> n, n) {
		vector< vector<int> > people;
		vector<int> data;
		rep(i, n) {
			int t;
			cin >> t;
			vector<int> vs = vector<int>(t);
			rep(j, t)
				cin >> vs[j];
			people.push_back(vs);
		}
		int k;
		cin >> k;
		data = vector<int>(k);
		rep(i, k)
			cin >> data[i];

		int cnt = 0, id;
		rep(i, people.size()) {
			if (subset(data, people[i]))
				cnt++, id = i+1;
		}

		cout << (cnt==1?id:-1) << endl;
	}
	return 0;
}

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

using namespace std;


int main(){
	int count;
	set <int> data[1001];
	while (1){
		cin >> count;
		if (!count)break;
		for (size_t i = 0; i < count; i++)
		{
			int count2;
			cin >> count2;
			for (size_t j = 0; j < count2; j++)
			{
				int data2;
				cin >> data2;
				data[i].insert(data2);
			}
			data[i].insert(100000);
		}
		int count3;
		cin >> count3;
		int a[1001];
		for (size_t i = 0; i < count3; i++)
		{
			int data3;
			cin >> data3;
			a[i] = data3;
		}
		int whois=-1;
		int count4 = 0;
		for (size_t i = 0; i < count; i++)
		{
			bool f = 1;
			for (size_t j = 0; j < count3; j++)
			{
				if (data[i].find(a[j]) == data[i].end()){
					//cout << a[j] << endl;
					f = 0;
					break;
				}
			}
			if (f){
				count4++;
				if (count4 == 2){
					whois = -1;
					break;
				}
				whois = i + 1;
			}
		}
			cout << whois << endl;
		//cout << count4 << whois << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

// A

bool info[110][110];
int data[110];

int main(){
    int N, M, p, K, i,j;
    
    while( cin >> N, N ){
        memset(info, false, sizeof(info));
        memset(data, 0, sizeof(data));

        for(i=1; i<=N; i++){
            cin >> M;
            for(j=0; j<M; j++){
                cin >> p;
                info[i][p] = true;
            }
        }

        cin >> K;
        for(i=0; i<K; i++){
            cin >> data[i];
        }

        int res = -1;
        int cnt = 0;
        for(i=1; i<=N; i++){
            for(j=0; j<K; j++){
                if( !info[i][data[j]] ) break;
            }
            if( j == K ){
                res = i;
                cnt++;
            }
        }

        cout << (cnt == 1 ? res : -1) << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  while(cin>>n,n){
    vector<Int> m(n);
    vector<vector<Int> > v(n);
    for(Int i=0;i<n;i++){
      cin>>m[i];
      v[i].resize(m[i]);
      for(Int j=0;j<m[i];j++)
	cin>>v[i][j];
    }
    
    Int k;
    cin>>k;
    set<Int> l;
    for(Int i=0;i<k;i++){
      Int x;
      cin>>x;
      l.emplace(x);
    }
    
    vector<Int> ans;
    for(Int i=0;i<n;i++){
      Int cnt=0;
      for(Int j=0;j<m[i];j++)
	cnt+=l.count(v[i][j]);
      
      if(cnt==k) ans.emplace_back(i);
    }
    
    if(ans.size()==1u) cout<<ans[0]+1<<endl;
    else cout<<-1<<endl;
  }
  return 0;
}