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 INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;


signed main() {
	
	while(1) {
		
		//input
		cin1(n);
		if (n == 0) break;

		vvi g(n,vi(n,0));
		rep(i,0,n) {
			cin1(m);
			rep(j,0,m) {
				cin1(a);
				g[i][a-1] = 1;
			}
		}

		int k; cin1(k);
		vi K(k,0);
		rep(i,0,k) {
			cin1(K[i]);
		}

		//solve
		int sum = 0;
		int ans = 0;
		rep(i,0,n) {
			bool flag = true;
			rep(j,0,k) {
				if (g[i][K[j]-1] == 0) {
					flag = false;
				}
			}
			if (flag) {
				sum++;
				ans = i + 1;
			}

		}
			if (sum == 1) {
				cout(ans);
			}else {
				cout(-1);
			}

		
	

	}

	return 0;
}

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

int main(){
  int N;
  while(cin >> N){
    if(N == 0) break;

    vector<vector<int> > p(N);
    for(int i = 0 ; i < N ; ++i){
      int M;
      cin >> M;
      for(int j = 0 ; j < M ; ++j){
	int pij;
	cin >> pij;
	p[i].push_back(pij);
      }
    }
    
    int K;
    cin >> K;
    vector<int> l(K);
    for(int i = 0 ; i < K ; ++i){
      cin >> l[i];
    }
      int ans=0;
      for(int i = 0 ; i < N ; ++i){
	int cnt = 0;
	for(int j = 0 ; j < K ; ++j){
	  for(unsigned int k = 0 ; k < p[i].size() ; ++k){
	    if(l[j] == p[i][k]){
	      ++cnt;
	    }
	  }
	}
	  if(cnt == K){
	    if(ans == 0){
	      ans = i + 1;
	    }else{
	      ans = -1;
	    }
	  }
	  
      }
      if(ans == 0){
	ans = -1;
      }else{
	cout << ans << endl;
      }
  }
  
}

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 fr first
#define sc second
#define fs fr
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef long long ll;

vi lists[1200];

bool check(int res, int idx){
	rep(i,lists[idx].size()){
		if(lists[idx][i] == res){
			return true;
		}
	}
	return false;
}
	

int main(){
	int N;
	while(cin >> N,N){
		rep(i,1200){
			lists[i].clear();
		}
		rep(i,N){
			int A;
			cin >> A;
			rep(j,A){
				int t;
				cin >> t;
				--t;
				lists[i].pb(t);
			}
			sort(lists[i].begin(),lists[i].end());
		}

		int P;
		cin >> P;
		vi s(P);
		rep(i,P){
			cin >> s[i];
			--s[i];
		}
		sort(s.begin(),s.end());
		
		int ans = -1;
		bool is_ans = false;
		rep(i,N){
			bool flg = true;
			rep(j,P){
				if(!check(s[j],i)){
					flg = false;
					break;
				}
			}
			if(flg && ans == -1){
				ans = i;
			}
			else if(flg && ans != -1){
				is_ans = true;
				cout << -1 << endl;
				break;
			}
		}
		if(ans == -1){
			ans = -2;
		}
		if(!is_ans){
			cout << ans+1 << endl;
		}
		

	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;


int main() {
	int n;
	while(cin >> n, n) {
		vector< vector<int> > f;
		REP(i, n) {
			int m; cin >> m;
			vector<int> hoge;
			REP(j, m) {
				int in; cin >> in;
				hoge.push_back(in);
			}
			sort(hoge.begin(), hoge.end());
			f.push_back(hoge);
		}
		int k; cin >> k;
		int cnt, ans = 0;
		vector<int> l;
		REP(i, k) {
			int in; cin >> in;
			l.push_back(in);
		}

//		REP(i, n) REP(j, f[i].size()) cout << i << ' ' << j << ' ' << f[i][j] << endl;
		REP(i, n) {
			cnt = 0;
			REP(j, f[i].size()) {
				if(f[i][j] == l[cnt])
					cnt++; 
				if(cnt == k) {
					if(!ans) ans = i+1;
					else ans = -1;
					break;
				}
			}
		}
		if(ans == 0) ans = -1;
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

int main() {
	int n;
	while(cin >> n, n) {
		bool know[101][101] = {};
		rep(i, n) {
			int m;
			cin >> m;
			rep(j, m) {
				int p;
				cin >> p;
				know[i+1][p] = true;
			}
		}
		int k;
		cin >> k;
		bool no[101] = {};
		rep(i, k) {
			int l;
			cin >> l;
			for(int j=1; j<=n; j++) {
				if(!know[j][l]) {
					no[j] = true;
				}
			}
		}
		int cri = 0;
		for(int i=1; i<=n; i++) {
			if(!no[i]) {
				if(cri==0)
					cri = i;
				else
					cri = -1;
			}
		}
		if(cri==0) cri = -1;
		cout << cri << endl;
	}
	return 0;
}