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 "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl; 
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)            for (auto i : v)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define pb(x)                 push_back(x)
#define bp(x)                 __builtin_popcount(x)
#define mp(x, y)              make_pair((x), (y))
#define fi                    first
#define se                    second
#define setp(x)               setprecision(x)
#define mset(m, v)            memset(m, v, sizeof(m))
#define sz(x)                 (int)(x.size())
static const int INF        = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD        = 1000000007;
static const double PI      = 3.14159265358979;

//#define int                   long long

typedef vector<double>        vd;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef vector<int>           vi;
typedef pair<int, int>        pii;
typedef vector<pii>           vpii;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int _x; scanf("%d", &_x); return _x; }
long long lin() {long long _x; scanf("%lld", &_x); return _x; };

signed main() { 
        int n;
        while (cin >> n) {
                if (!n) break;
                vector<vi> p(n);
                rep(i, n) {
                        int m;
                        cin >> m;
                        vi tmp(m);
                        rep(j, m) {
                                int a;
                                cin >> a;
                                a --;
                                p[i].pb(a);
                        }
                }
                int k = in();
                vi l(k);
                rep(i, k) {
                        cin >> l[i];
                        l[i] --;
                }
                vb f(n, 0);
                rep(i, k) {
                        rep(j, n) {
                                rep(h, p[j].size()) {
                                        if (p[j][h] == l[i]) {
                                                f[j] = true;
                                                goto out;
                                        }
                                        else f[j] = false;
                                }                             
                                out:;
                        }
                }
                vi ans;
                rep(i, n) if (f[i]) ans.pb(i);
                if (sz(ans) != 1) cout << -1 << endl;
                else cout << ans[0] + 1 << endl;
        }
        return 0;
}

C++: #include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	
	int n;
	int b[100][100]={};
	
	while( cin >> n && n!=0)
	{
		
		REP(i,n){REP(j,n){b[i][j]=0;}}
		
		REP(i,n)
		{
			int k;
			cin >> k;
			REP(j,k)
			{
				int l;
				cin >> l;
				b[i][l-1] ++;
			}
		}

		int hanin[100]={};
		REP(i,n){	hanin[i]=1;}
		
		int k;
		cin >> k;
		REP(i,k)
		{
			int l;
			cin >> l;
			REP(j,n){
			if(b[j][l-1]==0){	hanin[j] =0;	}
		}}
		
		int sum(0);
		int ans(0);
		REP(i,n){ if(hanin[i]==1){sum+=hanin[i];	ans+=(i+1);}}
		
		if(sum==1){	cout << ans << endl;	}
		else cout << -1 << endl;
		
	}
	return 0 ;
}

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    while(1){
        int n;
        cin>>n;
        if(n==0)break;
        int data[n+1][101],cnt[n];
        for(int s=1;s<=n;s++){
            int k;
            cin>>k;
            for(int i=0;i<k;i++)cin>>data[s][i];
            cnt[s]=k;
        }
        int tsu;
        cin>>tsu;
        int target[tsu];
        for(int i=0;i<tsu;i++)cin>>target[i];
        //until input
        
        //under seach
        int cnts=0,memo;
        for(int s=1;s<=n;s++){
            int z=0;
            for(int i=0;i<cnt[s];i++){
                for(int t=0;t<tsu;t++){
                    if(data[s][i]==target[t])z++;
                }
            }
            if(z==tsu){
                cnts++;
                memo=s;
            }
        }
        if(cnts==0)cout<<"-1\n";
        else if(cnts>1)cout<<"-1\n";
        else if(cnts==1)cout<<memo<<endl;
    }
    
    
    
    return 0;
}