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 <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;
    
    vector<vector<bool>> x(n, vector<bool>(n, false));
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      for (int j = 0; j < m; j++) {
        int p;
        cin >> p;
        p--;
        x.at(i).at(p) = true;
      }
    }
    
    int k;
    cin >> k;
    vector<int> y(k);
    for (int i = 0; i < k; i++) {
      cin >> y.at(i);
      y.at(i)--;
    }
    
    vector<int> ans;
    for (int i = 0; i < n; i++) {
      bool flag = true;
      for (int j = 0; j < k; j++) {
        if (x.at(i).at(y.at(j)) == false) flag = false;
      }
      if (flag) ans.emplace_back(i + 1);
    }
    
    if (ans.size() != 1) cout << "-1\n";
    else cout << ans.at(0) << '\n';
  }
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main(void) {
    int N;
    while (cin >> N, N) {
        vector<vector<int>> p(N);
        int M, tmp;
        for (int i = 0; i < N; i++) {
            cin >> M;
            for (int j = 0; j < M; j++) {
                cin >> tmp;
                p[i].push_back(tmp);
            }
        }
        int K;
        cin >> K;
        vector<int> l(K);
        for (int i = 0; i < K; i++) cin >> l[i];

        bool flag = false;
        int ans = -1;
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < K; k++) {
                flag = false;
                for (int j = 0; j < p[i].size(); j++) {
                    if (l[k] == p[i][j]) flag = true;
                }
                if (!flag) break;
            }
            if (flag) {
                if (ans == -1) {
                    ans = i+1;
                } else {
                    ans = -1;
                    break;
                }
            }
        }

        cout << ans << 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>
#include <vector>
#include <algorithm>
using namespace std;

int n, k;
int m[102];
int t[102][102];
int r[102];

int main(){
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      cin >> m[i];
      for(int j = 0; j < m[i]; j++){
        cin >> t[i][j];
      }
    }

    cin >> k;

    for(int i = 0; i < k; i++){
      cin >> r[i];
    }

    vector<int> v;

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

      for(int j = 0; j < k; j++){
        if(find(t[i], t[i] + m[i], r[j]) == t[i] + m[i]){
          flg = false;
          break;
        }
      }

      if(flg) v.push_back(i + 1);
    }

    if(v.size() == 1){
      cout << v[0] << endl;
    }
    else{
      cout << "-1\n";
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n) {
    int m,x;
    bool a[n+1][n+1];
    memset(a,false,sizeof(a));
    REP(i,1,n+1) {
      cin >> m;
      rep(j,m) {
	cin >> x;
	a[i][x]=true;
      }
    }
    cin >> m;
    bool b[n+1];
    memset(b,false,sizeof(b));
    rep(i,m) {
      cin >> x;
      b[x]=true;
    }
    int ans=-1;
    REP(i,1,n+1) {
      bool ck=true;
      REP(j,1,n+1) {
	if(b[j] && !a[i][j]) ck=false;
      }
      if(ck) {
	if(ans==-1) ans=i;
	else ans=-2;
      }
    }
    if(ans==-1 || ans==-2) pr(-1);
    else pr(ans);
  }
  return 0;
}