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

int find(vector<int> kk, vector<vector<int>> a){
  int flag=0;
  int person=0;
  set<int> kkk(kk.begin(), kk.end());

  for(int j=0;j<a.size();j++){
    int cnt=0;
    for(int k=0;k<a[j].size();k++){
      if(kkk.find(a[j][k])!=kkk.end()){
         cnt++;
         if(cnt==kkk.size()){
           person=j+1;
           flag++;
         }
      }
    }
  }

  if(flag!=1)
    return 0;
  else
    return person;
}

int main(){
  int n;

  while(cin>>n&&n){
    vector<vector<int> > a(n);
    vector<int> cnt(n);
    vector<int> kk;

    for(int i=0;i<n;i++){
      cnt[i]=0;
    }

    for(int i=0;i<n;i++){
      int m;
      cin >> m;
      for(int j=0;j<m;j++){
        int p;
        cin >> p;
        a[i].push_back(p);
        cnt[p]++;
      }
    }


    int k;
    cin >> k;
    int person;
    for(int i=0;i<k;i++){
      int l;
      cin >> l;
      kk.push_back(l);
    }

    person = find(kk, a);

    if(person!=0) cout << person << endl;
    else cout << -1 << endl;

  }

  return 0;
}

C++: #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() {

	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);
		}

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

		vector<int> suspect;
		REP(i,n) {
			vector<int> is;
			set_intersection(
				ALL(g_leak), ALL(g_p[i]),
				std::inserter(is, is.end())
			);
			if (is.size()!=g_leak.size()) continue;
			suspect.push_back(i);
		}

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

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

int main(){

int N;
while(1){
cin>>N;
int M;
bool n[25][25]={};
for(int i=1;i<=N;i++){
cin>>M;
for(int j=0;j<M;j++)
{int x;cin>>x;n[i][x]=true;}
}

bool R[25]={};
cin>>M;
for(int i=0;i<M;i++)
{int x;cin>>x;R[x]=true;}
int c=0,k=0;

for(int i=1;i<=N;i++){bool f=true;
for(int j=1;j<=N;j++)
{
if(n[i][j]!=R[j]&&R[j]==true)f=false;
}
if(f==true){c++;k=i;}
}

if(c==1)cout<<k<<endl;
else{cout<<"-1"<<endl;}
}
return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(void){
    int n;
    while(true){
        int b;
        cin>>n;
        if(n==0)break;
vector<int> m(n);
vector<int> p,ans;
for(int i=0;i<n;i++){
    cin>>m[i];
    for(int j=0;j<m[i];j++){
int a;
cin>>a;
p.push_back(a);
    }
    
}
int k;
cin>>k;
vector<int> l(k);
for(int i=0;i<k;i++)
cin>>l[i];
int sum=0;
for(int i=0;i<n;i++){
    sum+=m[i];
    b=0;
    for(int j=0;j<k;j++){
        int t=0;
        for(int q=sum-m[i];q<sum;q++){
            if(l[j]==p[q])
            t++;
        }
        if(t==0)break;
        else b++;
    }
if(b==k) ans.push_back(i+1);
}
if(ans.size()==1){
    cout<<ans[0]<<endl;
}else{
    cout<<-1<<endl;
        
}
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstring>
#include <string>
#include <queue>
#include <cmath>
#include <map>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define rev(v) (v).rbegin(), (v).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> P;
typedef long long ll;

int dp[600000] = {};

int main(){
	int n;
	while(cin >> n, n){
		vector<vi> list(n);
		rep(i, n){
			int m;
			cin >> m;
			list[i].resize(m);
			rep(j, m) cin >> list[i][j];
		}

		vector<int> ok(n, 0);
		int k;
		cin >> k;
		rep(i, k){
			int l;
			cin >> l;
			rep(j, list.size()){
				if(ok[j]) continue;
				bool inc = false;
				rep(k, list[j].size()){
					if(list[j][k] == l){
						inc = true;
						break;
					}
				}
				ok[j] |= !inc;
			}
		}

		int cnt = 0;
		int ans;
		rep(i, n){
			if(!ok[i]){
				cnt++;
				ans = i+1;
			}
		}

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

	}


	return 0;
}

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

int main(){

    while(1){
        int n;
        cin >> n;
        if(n==0){
            break;
        }
        vector<vector<int>> p(n);
        for(int i=0;i<n;i++){
            int te;
            cin >> te;
            for(int j=0;j<te;j++){
                int t;
                cin >> t;
                p[i].push_back(t);
            }
        }
        for(int i=0;i<n;i++){
            sort(p[i].begin(),p[i].end());
        }
        vector<bool> f(n,true);
        int k;
        cin >> k;
        for(int i=0;i<k;i++){
            int t;
            cin >> t;
            for(int j=0;j<n;j++){
                if(f[j]){
                    if(!binary_search(p[j].begin(),p[j].end(),t)){
                        f[j]=false;
                    }
                }
            }
        }
        int ans;
        int cnt=0;
        for(int i=0;i<n;i++){
            if(f[i]){
                ans=i+1;
                cnt++;
            }
        }
        if(cnt==1){
            cout << ans << endl;
        }else{
            cout << -1 << endl;
        }
    }

    return 0;
}