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>
#include<algorithm>
using namespace std;
#define ALL(a) a.begin(),a.end()
int main(){
  int n;
  while( cin >> n , n ){
    vector < int > p[n],L,tmp;
    for(int i = 0, q, d ; i < n ; i++ ){
      cin >> q;
      while(q--) cin >> d, p[i].push_back(--d);
      sort(ALL(p[i]));
    }
    int K, l, ans = -1, i;
    cin >> K;
    while(K--) cin >> l, L.push_back(--l);
    for( i = 0 ; i < n ; i++ ){
      if(includes(ALL(p[i]),ALL(L))){
        if(ans == -1) ans = i + 1;
        else break;
      }
    }
    cout << (i == n ? ans : -1) << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	int64 N;
	while(cin >> N && N){
		vector<set<int64>> p(N, set<int64>());
		vector<int64> l;
		REP(i, N){
			int32 M;
			cin >> M;
			int64 x;
			REP(j, M){ cin >> x; p[i].insert(x); }
		}
		int32 K;
		cin >> K;
		l.resize(K);
		REP(i, K) cin >> l[i];

		int32 res = -1;
		bool ok = 1;
		REP(i, N){
			bool ok2 = 1;
			REP(j, K){
				if(p[i].find(l[j]) == p[i].end()) ok2 = 0;
			}
			if(ok2){
				if(res != -1) ok = 0;
				res = i+1;
			}
		}
		cout << (ok && res != -1 ? res : -1) << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) for(int i=0;i<n;i++)
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vlai=valarray<int>;

int main(void){
    int n;
    while(cin>>n,n){
        vector<set<int>> kl(n+1);
        rep(i,n+1){
            int m;cin>>m;
            rep(j,m){int k; cin>>k; kl[i].insert(k);}
        }
        int ans=-1;
        rep(i,n){
            if(includes(all(kl[i]), all(kl[n]))){
                if(ans==-1){
                    ans=i+1;
                }else ans=-2;
            }
        }
        cout<<(ans<0?-1:ans)<<endl;
    }
}

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

bool contains(vector<int>& a, vector<int>& b) {
    for(int& i : b) {
        if(find(begin(a), end(a), i) == end(a)) return false;
    }
    return true;
}

int main() {
    int n;
    vector<int> p[100];
    vector<int> l;
    while(true) {
        cin >> n;
        if(n == 0) break;
        for(int i = 0; i < n; ++i) {
            int m; cin >> m;
            p[i].resize(m);
            for(int j = 0; j < m; ++j) {
                cin >> p[i][j];
                p[i][j];
            }
        }
        int k; cin >> k;
        l.resize(k);
        for(int i = 0; i < k; ++i) {
            cin >> l[i];
        }

        vector<int> ans = vector<int>();
        for(int i = 0; i < n; ++i) {
            if(contains(p[i], l)) {
                ans.push_back(i);
            }
        }
        cout << (ans.size() == 1 ? ans[0] + 1 : -1) << endl;
    }
    return 0;
}