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++: //#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n;
    while(cin>>n, n) {
        bool table[101][101];
        fill((bool*)table, (bool*)table+101*101, false);
        for(int i=0; i<n; ++i) {
            int m;
            cin >> m;
            for(int j=0; j<m; ++j) {
                int x;
                cin >> x;
                table[i][x] = true;
            }
        }
        int k;
        cin >> k;
        vector<int> target(k);
        for(int i=0; i<k; ++i) cin >> target[i];

        int ans = -1;
        for(int i=0; i<n; ++i) {
            int j;
            for(j=0; j<k; ++j)
                if(!table[i][target[j]]) break;
            if(j == k) {
                if(ans != -1) {
                    ans = -1;
                    break;
                }
                else ans = i + 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {

    int n;
    while (cin >> n, n) {
        vector<int> m[n];

        rep(i, n) {
            int mm;
            cin >> mm;
            rep(j, mm) {
                int p;
                cin >> p;
                m[i].push_back(p);
            }
            sort(m[i].begin(), m[i].end());
        }

        int kk;
        cin >> kk;
        vector<int> k(kk);

        rep(i, kk) {
            int l;
            cin >> l;
            k[i] = l;
        }
        sort(k.begin(), k.end());

        vector<int> ans;
        rep(i, n) {
            if (k.size() > m[i].size()) continue;
            int idx=0;
            rep(j, m[i].size()) {
                if (idx < k.size() and k[idx] == m[i][j]) idx++;
            }
            if (idx == k.size()) {
                ans.push_back(i+1);
            }
        }
        if (ans.size() == 1) { cout << ans[0] << endl; }
        else { cout << "-1" << endl; }
    }
}

C++: #include <iostream>
#include <vector>

using namespace std;

int main(){

	int n;

	while(cin>>n){
		if(n==0)break;

		vector<int> *v;
		v = new vector<int>[n];

		int m;
		for(int i=0;i<n;i++){
			cin>>m;
			for(int j=0;j<m;j++){
				int tmp;
				cin>>tmp;
				v[i].push_back(tmp);
			}
		}
		int *l;
		int *flag;
		int k;
		cin>>k;
		l = new int[k];
		flag = new int[k];

		for(int i=0;i<k;i++)cin>>l[i];

		int num=-1;
		for(int i=0;i<n;i++){
			for(int m=0;m<k;m++){
				flag[m] = 0;
			}
			for(int m=0;m<k;m++){
				for(int j=0;j<v[i].size();j++){
					if(l[m] == v[i].at(j)){
						flag[m]=1;
						break;
					}
				}
			}
			int state=0;
			for(int m=0;m<k;m++){
				if(flag[m]==0)state=1;
			}
			if(state==0){
				if(num==-1){
					num=i+1;
				}
				else{
					num=100000;
				}
			}
		}

		if(num==100000)cout<<-1<<endl;
		else{cout<<num<<endl;}

	}
	return 0;
}