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 <iostream>
#include <vector>
using namespace std;

int main() {

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    vector< long long int > v0, v1;

    for ( long long int i = 0; i < n+1; i++ ) {

      long long int m;
      cin >> m;

      long long int p0 = 0;
      long long int p1 = 0;

      for ( long long int j = 0; j < m; j++ ) {

	long long int in;
	cin >> in;
	if ( in < 50 ) {
	  p0 += ( 1 << in );
	}else {
	  p1 += ( 1 << ( in - 50 ) );
	}

      }

      v0.push_back( p0 );
      v1.push_back( p1 );

    }

    long long int ans = -1;

    for ( long long int j = 0; j < n; j++ ) {

      if ( ( v0[i] & v0[n] ) == v0[n] && ( v1[i] & v1[n] ) == v1[n] ) {

	if ( ans == -1 ) {
	  ans = i + 1;
	}else {
	  ans = -1;
	  break;
	}

      }

    }

    cout << ans << endl;

  }

  return 0;

}

C++: #include <set>
#include <cstdio>
#include <queue>
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  while(int n = getInt()){
    vector<vector<int> > v(n);
    REP(i,n){
      int m = getInt();
      REP(j,m) v[i].push_back(getInt());
    }

    int k = getInt();
    REP(i,k){
      int r = getInt();
      for(auto &vv : v){
	auto it = find(vv.begin(), vv.end(), r);
	if(it != vv.end()) *it = -1;
      }
    }

    vector<int> ans;
    REP(i,n) if(count(v[i].begin(), v[i].end(), -1) == k)
      ans.push_back(i + 1);
    printf("%d\n", ans.size() == 1 ? ans[0] : -1);
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;


int main(){
	int N;
	while(cin>>N,N){
		set<int> know[101];
		vector<int> ans,rouei;
		bool flag[101]={false};
		int a,M,K;
		REP(i,1,N+1){
			cin>>M;
			REP(j,0,M){
				cin>>a;
				know[i].insert(a);
			}
		}
		cin>>K;
		REP(i,0,K){
			cin>>a;
			rouei.push_back(a);
			flag[a]=true;
		}

		REP(i,1,N+1){
			if(!flag[i]){
				for(unsigned int j=0;j<rouei.size();j++){
					if(know[i].find(rouei[j])==know[i].end()){
						flag[i]=true;
						break;
					}
				}
				if(!flag[i]){
					ans.push_back(i);
				}
			}
		}
		if(ans.size()==1){
			p(ans[0]);
		}else{
			p("-1");
		}
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
struct XY
{
	int x;
	int y;
};
int in()
{
	int x;
	cin >> x;
	return x;
}
/*
(char)'1' - (int)48 = (int)1;
???1111181
*/
////////////////////////////////////////////////////



int main()
{
	int n;
	while (cin>>n&&n)
	{
		vector<int>  m[120];
		int k[120] = {};
		rep(i, n)
		{
			int nn = in();
			rep(l,nn)
			{
				m[i].push_back(in());
			}
			sort(m[i].begin(), m[i].end());
		}
		int nn = in();
		rep(i, nn)
		{
			int x = in();
			rep(l, n)
			{
				if (!binary_search(m[l].begin(), m[l].end(), x))
				{
					k[l] = 1;
				}
			}
		}
		if (count(k, k + n, 0) != 1)
		{
			cout << -1 << endl;
		}
		else
		{
			int ans = 0;
			rep(i, n)if (k[i] == 0)ans = i + 1;
			cout << ans << endl;
		}
	}
}

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

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {

		vector<vector<int>>list(n, vector<int>(n, 0));
		int number;

		for (int i = 0;i < n;i++) {
			cin >> number;
			for (int j = 0;j < number;j++) {
				int codename;
				cin >> codename;
				list[i][codename - 1] = 1;
			}
		}//list[a][b]:a know b

		cin >> number;
		
		vector<int>ans(n,1);
		int leaked;
		for (int i = 0;i < number;i++) {
			cin >> leaked;
			for (int j = 0;j < n;j++) {
				if (list[j][leaked - 1] == 0) ans[j] = 0;
			}
		}//who is imposible
		int sum = 0,telltale;

		for (int i = 0;i < n;i++) {
			sum += ans[i];
			if (ans[i] == 1) telltale = i + 1;
		}

		if (sum == 1)cout << telltale << endl;
		else cout << -1 << endl;

	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const int MAX_N=100;
set<int> v[MAX_N];
vector<int> l;
int n;

void solve(){
  int result=-1;
  REP(i,n){
    for(int a:l){
      if(v[i].count(a)==0){goto E;}
    }
    if(result==-1)
      result=i+1;
    else{
      cout<<-1<<endl;
      return;
    }
  E:;
  }
  cout<<result<<endl;
}

int main(){ _;
  int m,k,tmp;
  while(cin>>n,n!=0){
    REP(i,n){
      v[i].clear();
      cin>>m;
      REP(j,m){
	cin>>tmp;
	v[i].insert(tmp);
      }
    }
    l.clear();
    cin>>k;
    REP(i,k){
      cin>>tmp;
      l.push_back(tmp);
    }
    solve();
  }
}