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<iomanip>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<map>
#include<cstdlib>
#include<cctype>
#include<string>

using namespace std;

typedef long long ll;
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;

const int d[]={0,1,0,-1};

#define SQR(x) ((x)*(x))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define reps(i,j,n) for(int i = (j) ; i < (n) ; ++i )
#define rep(i,j) reps(i,0,j)
#define INF (1 << 30)
#define dout(x,n) fixed << setprecision(n) << x

int getint(){ int x; cin >> x; return x;}
string itos(int v) {stringstream ss;ss<<v;return ss.str();}
int stoi(string s) {int v; stringstream ss(s);ss>>v;return v;}

int main(){
  int N,M,k[101];
  bool p[101][101];
  while(cin >> N , N){
    fill_n(p[0],101*101,false);
    fill_n(k,101,1);
    rep(i,N){
      cin >> M;
      rep(j,M){
        int a = getint() - 1;
        p[i][a] = true;
      }
    }
    cin >> M;
    rep(i,M){
      int a = getint() - 1;
      rep(j,N) if(!p[j][a]) k[j] = 0;
    }
    int sum = 0;
    rep(i,N) sum += k[i];
    if(sum != 1) cout << -1 << endl;
    else rep(i,N){
        if(k[i]){
          cout << i + 1 << endl;
          break;
      }
      }
  }
}

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

int main(){
	  while(1){
			int N;
			cin >> N;
			if(!N) break;

			vector<set<int> > list(N);
			for(int i=0; i<N; i++){
				  int M; cin >> M;
				  for(int j=0; j<M; j++){
						int tmp; cin >> tmp;
						list[i].insert( tmp );
				  }
			}
			int K; cin >> K;
			vector<int> l(K);
			for(int i=0; i<K; i++)  cin >> l[i];

			int hannin = -2;
			for(int i=0; i<N; i++){
				  for(int j=0; j<K; j++){
						if(list[i].find( l[j] ) == list[i].end()) goto L1; // ????????§??????
				  }
				  if(hannin == -2) hannin = i;
				  else{
						hannin = -2;
						goto L2;
				  }
			L1:;
			}
			
			
	  L2:
			cout << hannin+1 << endl;
			
	  }
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    while (cin >> n && n){
        int d[100][100] = {};
        REP(i,n){
            int p;
            cin >> p;
            while (p--){
                int a;
                cin >> a;
                d[i][a] = 1;
            }
        }
        int m;
        cin >> m;
        VI l(m);
        REP(i,m) cin >> l[i];
        int ans = -1;
        bool g = 1;
        REP(i,n){
            bool f = 1;
            REP(j,m) f &= d[i][l[j]];
            if (f) {
                if (ans > 0) g = 0;
                else ans = i+1;
            }
        }
        cout << (g ? ans : -1) << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#include<sstream>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))
#define ALL(c) (c).begin(), (c).end()
#define dump(a) cerr << #a << "=" << (a) << endl
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> void chmin(T &t, T f) { if (t > f) t = f; } //t=min
template<class T> void chmax(T &t, T f) { if (t < f) t = f; } //t=max
using namespace std;

int main() {
	int N,M,p;
	int K,l;

	while(cin >> N, N) {
		vector<vector<int> > infos;
		vector<int> out_infos;

		rep(n,N) {
			cin >> M;
			vector<int> info;
			rep(m,M) {
				cin >> p;
				info.push_back(p); //0オリジン			
			}
			infos.push_back(info);
		}
		cin >> K;
		rep(k,K) {
			cin >> l;
			out_infos.push_back(l);
		}
		
		vector<int> bad_mans;
		rep(i,N) {
			bool is_all_find = true;
			rep(k,K) {
				if (! binary_search(ALL(infos[i]),out_infos[k])) { //見つからない!
					is_all_find = false;
				}
			}
			if (is_all_find) {
				bad_mans.push_back(i+1);
			}
		}
		if (bad_mans.size() == 1) {
			cout << bad_mans.front() << endl;
		}
		else { //犯人が0人，または2人以上で特定できないとき
			cout << -1 << endl;
		}


		infos.clear();
		out_infos.clear();
	}

	return 0;
}