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++: //============================================================================
// Name        : A.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#define  rep(i,a) for(int i = 0; i < int(a); i++)
#include <vector>
using namespace std;

int main() {
	int K[101], k;

	vector<int> G[101];
	int N, M, x;
	while (true ) {
		cin >> N ;
		if (N == 0) break;
		rep(i, N) {
			G[i].clear();
		}
		rep(i,N) {
			cin >> M;
			rep(j,M) {
				cin >> x;
				G[i].push_back(x);
			}
		}
		cin >> k ;
		rep(i, k) cin >> K[i];
		int num = 0, vt;
		rep(i, N) {
			bool ok = true;
			rep(j, k) {
				bool flag = false;
				rep(z, G[i].size()) {
					if (G[i][z] == K[j]) {
						flag = true;
						break;
					}
				}
				if (!flag) {
					ok = false;
					break;
				}
			}

			if (ok) {
				num ++ ;
				vt = i;
	 		}
			}
		if (num != 1)
			cout << -1 << endl;
		else {
			cout << vt + 1 << endl;
		}
	}
	return 0;
}

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

#define all(x) (x).begin(), (x).end()

using namespace std;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    int m;
    int k;
    int cnt;
    int ans;
    vector< vector<int> > p;
    vector<int> l;

    while(cin >> n, n){

        p.resize(n);

        for (auto &x : p){

            cin >> m;
            x.resize(m);

            for (auto &y : x)
                cin >> y;

        }


        cin >> k;
        l.resize(k);

        for(auto &x : l)
            cin >> x;

        sort(all(l));

        cnt = 0;
        ans = 0;

        for (int i = 0; i < n; i++){

            sort(all(p[i]));

            if(includes(all(p[i]), all(l))){
                cnt++;
                ans = i + 1;
            }

        }

        if(cnt != 1)
            cout << -1 << endl;
        else
            cout << ans << endl;

    }

    return 0;
}

C++: #include<iostream>
using namespace std;
bool comp[101][101];
int main(){
  int n;
  int num;
  while(cin>>n,n){
    
    for(int i=0;i<n;i++){
      cin>>num;
      for(int j=0;j<num;j++){
	int tmp; cin>>tmp;
	comp[i][tmp-1]=true;
      }
    }

    cin>>num;
    int list[num];
    for(int i=0;i<num;i++)cin>>list[i];

    int ans=-1;
    bool flag=false;
    int a=-1;
    for(int i=0;i<n;i++){
      ans=0;
      for(int j=0;j<num && comp[i][list[j]-1]==true; j++){
	//cout << "list["<<j<<"] = "<< list[j]-1<< endl;
	ans=j+1;
      }
      if(ans==num){
	if(flag==false){
	  a=i+1;
	  flag=true;
	}else{
	  a=-1;
	  break;
	}
      }
    }
    cout << a << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

int solve(int n) {
    vector<set<int>> p(n);
    REP(i,n) {
        int m;
        cin>>m;
        REP(j,m) {
            int t;
            cin>>t;
            p[i].insert(t);
        }
    }
    int k;
    cin>>k;
    vector<int> l(k);
    REP(i,k) cin>>l[i];

    int ans=-1;
    REP(i,n) {
        bool criminal=true;
        REP(j,k) {
            if(!CONTAIN(p[i],l[j])) {
                criminal=false;
                break;
            }
        }
        if(criminal) {
            if(ans!=-1) {
                return -1;
            }
            ans=i+1;
        }
    }
    return ans;
}
signed main() {
    while(1) {
        int n;
        cin>>n;
        if(n==0) break;
        cout<<solve(n)<<endl;
    }
    return 0;
}