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 <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    while(1){
        ll n; cin >> n;
        if(!n) break;
        vvl v(n);
        rep(i,n){
            ll m; cin >> m;
            rep(j,m){
                ll p; cin >> p;
                v[i].push_back(p);
            }
            sort(all(v[i]));
        }
        ll k; cin >> k;
        vl l(k); rep(i,k) cin >> l[i];
        ll ans = -1;
        rep(i,n){
            bool flag = true;
            rep(j,k){
                if(!binary_search(all(v[i]),l[j])){
                    flag = false;
                    break;
                }
            }
            if(flag){
                if(ans == -1) ans = i+1;
                else{
                    ans = -1;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N, K;
    vector<int> ans;
    while(true){
        int res = -1;
        cin >> N;
        if(N == 0) break;
        vector<int> work[N];
        vector<int> leak;
        rep(i, N){
            int M; cin >> M;
            rep(j, M){
                int temp; cin >> temp;
                work[i].push_back(temp);
            }
        }
        cin >> K;
        rep(i, K){
            int temp; cin >> temp;
            leak.push_back(temp);
        }
        rep(i, N){
            bool all_ok = true;
            rep(j, leak.size()){
                bool part_ok = false;
                rep(k, work[i].size()){
                    if(leak[j] == work[i][k]) part_ok = true;
                }
                if(!part_ok) all_ok = false;
            }
            if(all_ok && res != -1){
                res = -1;
                break;
            }
            else if(all_ok) res = i+1;
        }
        ans.push_back(res);
    }
    rep(i, ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main(void){
	int n;
	while(cin>>n,n){
		std::set<int> a[100];
		std::vector<int> s;
		int m,k;
		for(int i=0;i<n;i++){
			cin>>m;
			for(int j=0;j<m;j++){
				cin>>k;
				a[i].insert(k);
			}
		}
		int z;
		cin>>k,z;
		for(int i=0;i<k;i++){
			cin>>z;
			s.push_back(z);
		}

		int c=0;
		int number=9999;
		int i,j;
		for(i=0;i<n;i++){
			if(a[i].size()<s.size())continue;
			for(j=0;j<s.size();j++){
				if(a[i].find(s[j])==a[i].end())break;
			}
			if(j==s.size())c++;
			if(j==s.size())number=i+1;
			if(c==2)break;
		}
		if(c==1)cout<<number<<endl;
		else cout<<"-1"<<endl;
	}
	return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

int main() {
  int n;
  while(cin >> n, n) {
    bitset<100> know[100];
    bitset<100> leak;
    REP(i, n){
      int m;
      cin >> m;
      REP(j, m){
        int p;
        cin >> p;
        know[i][--p] = 1;
      }
    }
    int k;
    cin >> k;
    REP(i, k) {
      int l;
      cin >> l;
      leak[--l] = true;
    }

    int res = -1;
    REP(i, n){
      if ((know[i] & leak) == leak) {
        if (res != -1) {
          res = -1;
          break;
        }
        res = i + 1;
      }
    }
    cout << res << endl;
  }
}