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 <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define rall(a)		(a).rbegin(), (a).rend()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;


int main()
{
	int n;
	while (cin >> n && n){
		const int M = 102;
		
		int m[M];
		int p[M][M];
		clr(p);

		For(i,1, n+1){
			cin >> m[i];
			rep(j, m[i]){
				int t;
				cin >> t;
				p[i][t] = 1;
			}
		}
		bool f[M]; clr(f);

		int am;
		cin >> am;
		rep(i, am){
			int t;
			cin >> t;
			For(i,1, n+1){
				if (!p[i][t])f[i] = 1;
			}
		}

		int ans = -1; int sum = 0;
		For(i,1, n+1){
			if (!f[i]){
				ans = i; sum++;
			}
		}
		if (sum == 1)cout << ans << endl;
		else cout << -1 << endl;
		
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007LL;
const ll INF=1000000000LL;
const int MAX=100001;
int main(){
    int n;
    while(cin>>n,n){
    vector<int> p[110];
    for(int i=0;i<n;i++){
        int m;
        cin>>m;
        for(int j=0;j<m;j++){
            int pp;cin>>pp;
            p[i].push_back(pp);
            sort(all(p[i]));
        }
    }
    int k;
    cin>>k;
    vector<int> l;
    for(int j=0;j<k;j++){
        int ll;cin>>ll;
        l.push_back(ll);
    }
    sort(all(l));
    int c=0;
    int ans=0;
    for(int i=0;i<n;i++){
        if(includes(all(p[i]),all(l))){
            c++;
            ans=i+1;
        }
    }
    if(c!=1){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    }
    return 0;
}

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


int main(){
while(1){
  int i,j,N,M,k,l;
  cin>>N;
  if(N==0)return 0;
  int p[101][101]={0},lp[101]={0};
  for(i=0;i<N;i++){
    scanf("%d",&M);
    for(j=0;j<M;j++){
      scanf("%d",&k);
      p[i][k-1]=1;
    }
  }
  scanf("%d",&M);
  for(i=0;i<M;i++){
    scanf("%d",&k);
    lp[k-1]=1;
  }
  set<int> se;
  for(i=0;i<N;i++){
    //solve
    k=1;
    for(j=0;j<N;j++){
      if(p[i][j]<lp[j]){
        k=0;
        break;
      }
    }
    if(k==1){
      se.insert(i);
    }
  }
  if(se.size()==1){
    auto ans=*se.begin();
    printf("%d\n",ans+1);
  }else{
    printf("-1\n");
  }
  se.clear();
}
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  while (int N = in()){
    int bucket[128] = {};
    set<int> player[128];
    for (int i = 1; i <= N; i++){
      for (int M = in(); M--; ){
        int v = in();
        bucket[v]++;
        player[i].insert(v);
      }
    }
    vector<int> L;
    inpt(L, in(), in);
    vector<int> cand;
    for (int i = 1; i <= N; i++){
      bool ok = true;
      for (int l : L){
        if (!player[i].count(l)){
          ok = false;
          break;
        }
      }
      if (ok) cand.emplace_back(i);
    }
    if (cand.size() == 1){
      printf("%d\n", cand[0]);
    }
    else {
      printf("-1\n");
    }
  }
  return 0;
}