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>
#define reps(i,j,k) for(int i = j; i < k; ++i)
#define rep(i,j) reps(i,0,j)
#define pb push_back
#define fr first
#define fs fr
#define sc second
#define ll long long
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> Pii;


int main(){
	int n, m;
	while(cin >> n, n){
		vi m(n);
		vector<vi> p(n);
		rep(i,n){
			cin >> m[i];
			p[i].resize(m[i]);
			rep(j,m[i]){
				cin >> p[i][j];
				p[i][j]--;
			}
			sort(p[i].begin(), p[i].end());
		}
		int k;
		cin >> k;
		vi v(k);
		rep(i,k){
			cin >> v[i];
			v[i]--;
		}
		sort(v.begin(), v.end());
		int ans = -1;
		rep(i,n){
			bool f = true;
			rep(j, k){
				bool f2 = false;
				rep(l,m[i])
					if(p[i][l] == v[j]) f2 = true;
				if(!f2) f = false;
			}
			if(f){
				if(ans == -1) ans = i+1;
				else ans = -2;
			}
		}

		if(ans < 0) cout << (-1) << endl;
		else cout << ans << endl;

	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N;
  while(cin>>N && N){
    vector<int> ans;
    bool is[1000][1000] = {0};
    REP(i, N){
      int k; cin>>k;
      REP(j,k){
        int t; cin>>t;
        t--;
        is[i][t] = true;
      }
    }
    int k; cin>>k;
    bool row[1000] = {};
    REP(i, k){
      int t; cin>>t;
      t--;
      row[t] = true;
    }
    REP(i, N){
      bool ok = true;
      REP(j, N)if(row[j] && !is[i][j]) ok = false;
      if(ok) ans.push_back(i+1);
    }
    if(ans.size() == 1) cout<<ans.front()<<endl;
    else cout<<-1<<endl;
  }
  return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int N;
    while (cin >> N, N) {
        vector<set<int>> member(N+1);
        REP(i, N+1) {
            int M;
            cin >> M;
            REP(j, M) {
                int p;
                cin >> p;
                member[i].insert(p);
            }
        }

        int res = -1;
        REP(i, N) {
            bool leaked = true;
            for (int p : member[N]) {
                if (member[i].find(p) == member[i].end()) {
                    leaked = false;
                    break;
                }
            }
            if (leaked) {
                if (res == -1) {
                    res = i+1;
                } else {
                    res = -1;
                    break;
                }
            }
        }
        cout << res << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N;

int main(){

  while(cin>>N&&N){
    vector<int> v[101];
    for(int i=0;i<N;i++){
      int M;
      cin>>M;
      for(int j=0;j<M;j++){
	int p;
	cin>>p;
	v[i].push_back(p);
      }
    }
    vector<int> ls;
    int K;
    cin>>K;
    for(int i=0;i<K;i++){
      int l;
      cin>>l;
      ls.push_back(l);
    }
    vector<int> ans;
    for(int i=0;i<N;i++){
      bool aa=true;
      for(int j=0;j<(int)ls.size();j++){
	bool ok=false;
	for(int k=0;k<(int)v[i].size();k++){
	  if(v[i][k]==ls[j])ok=true;
	}
	if(!ok){
	  aa=false;
	  break;
	}
      }
      if(aa){
	ans.push_back(i);
	if(ans.size()>=2){
	  break;
	}
      }
    }
    if((int)ans.size()==1)
      cout<<ans[0]+1<<endl;
    else cout<<-1<<endl;
  }

  return 0;
}