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 <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int N;
  while(cin >> N, N) {
    bool info[N+1][N+1]; CLR(info);
    FOR(i,1,N+1) {
      int M; cin >> M;
      FOR(j,0,M) {
        int p; cin >> p;
        info[i][p] = true;
      }
    }
    int K; cin >> K;
    int l[K];
    FOR(i,0,K) cin >> l[i];
    int ans = 0, cnt = 0;
    FOR(i,1,N+1) {
      bool ok = true;
      FOR(j,0,K) {
        if(!info[i][l[j]]) {
          ok = false;
          break;
        }
      }
      if(ok) {
        if(cnt == 0) {
          cnt++;
          ans = i;
        } else {
          ans = -1;
          break;
        }
      }
    }
    if(ans == 0) ans = -1;
    cout << ans << endl;
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int N;
int K;
int M[103];
int p[103][103];
int l[103];

bool check(int i_) {
    rep(i,K) {
        rep(j,M[i_]) {
            if(l[i]==p[i_][j]) {
                goto go;
            }
        }
        return false;
go:;
    }
    return true;
}

void solve() {
    rep(i,103) {
        rep(j,103) p[i][j]=0;
        M[i]=0;
        l[i]=0;
    }
    rep(i,N) {
        cin>>M[i];
        rep(j,M[i]) {
            cin>>p[i][j];
        }
    }
    cin>>K;
    rep(i,K) cin>>l[i];

    int ans = -1;
    rep(i,N) {
        if(check(i)) {
            if(ans==-1) ans=i+1;
            else ans = -1;
        }
    }
    cout<<ans<<endl;
}

int main() {
    while(cin>>N) {
        if(!N) return 0;
        solve();
    }

    return 0;
}

C++: #include<iostream>
#include<sstream>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define each(i, c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

int n, m[100], p[100][100], k, l[100];

int main(){
	while(cin >> n, n){
		rep(i, n){
			cin >> m[i];
			rep(j, m[i]) cin >> p[i][j];
		}
		cin >> k;
		rep(i, k) cin >> l[i];
		
		int ans = -2;
		rep(i, n){
			rep(j, k){
				bool ok = 0;
				rep(h, m[i]) if(l[j] == p[i][h]) ok = 1;
				if(!ok) goto FAIL;
			}
			if(ans == -2) ans = i + 1;
			else ans = -1;
			FAIL:;
		}
		if(ans < 0) ans = -1;
		cout << ans << endl;
	}
	return 0;
}

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

int main(void){
    int n;
    
    while(cin>>n){
        if(n==0) break;
    int m[n],p[100][100]={0};
    for(int i=0;i<n;i++){
        cin>>m[i];
        for(int j=0;j<m[i];j++){
            cin>>p[i][j];
            }
    }
    int k;
    cin>>k;
    int l[k];
    for(int i=0;i<k;i++){
        cin>>l[i];
    }
    int s=0,ans[100]={-1};
    for(int i=0;i<n;i++){
        int g=0;
        bool div=true;
        while(div){
            div=false;
            for(int j=0;j<m[i];j++){
                if(l[g]==p[i][j]){
                    div=true;
                    g++;
                
                    if(g==k){
                        ans[s++]=i+1;
                    }
                }
            }
        }
    }
    if(ans[1]>0) cout<<-1<<endl;
    else cout<<ans[0]<<endl;
    
    }

}

C++: #include <set>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int x,n,m,k,i,r;
	for(;scanf("%d",&n),n;printf("%d\n",r)){
		vector<set<int> >v;
		for(i=0;i<n;i++){
			set<int>s;
			for(scanf("%d",&m),k=0;k<m;k++)scanf("%d",&x),s.insert(x);
			v.push_back(s);
		}
		set<int>t;
		for(scanf("%d",&k),m=0;m<k;m++)scanf("%d",&x),t.insert(x);
		for(r=-1,k=0;k<n;k++){
			set<int>s;
			set_intersection(v[k].begin(),v[k].end(),t.begin(),t.end(),inserter(s,s.end()));
			if(s.size()==t.size()){if(~r){r=-1;break;}r=k+1;}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}

int a[1000][1000];
int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    int b,d;
    lp(i,n){
      cin>>b;
      lp(j,b){
	cin>>d;
	a[i][d]=1;
      }
    }
    int count=0,ans=0,check;
    int c;
    cin>>c;
    int x[1000];
    lpin(x,i,c);
    lp(i,n){
      check=0;
      lp(j,c){
	if(a[i][x[j]]==1) 1;
	else check=1;
      }
      if(check==0){
	ans=i;
	count++;
      }
    }
    if(count==1) cout<<ans+1<<endl;
    else cout<<"-1"<<endl;
  }
  return 0;
}