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>
#include<utility>
#include<bitset>
using namespace std;
int main(int argc, char *argv[])
{
  const int N = 100;
  for(int t = 1;; t++) {
    int n;
    cin >> n;
    if(n == 0) break;
    vector<bitset<N>> mat;
    auto read = [](){
      int m;
      cin >> m;
      bitset<N> vs;
      for(int j = 0; j < m; j++) {
        int p;
        cin >> p;
        vs[p-1] = true;
      }
      return move(vs);
    };
    for(int i = 0; i < n; i++) {
      mat.push_back(read());
    }
    bitset<N> ls = read();
    int cnt = 0;
    int idx = -1;
    for(int i = 0; i < n; i++) {
      if(ls == (ls & mat[i])) {
        cnt++;
        idx = i + 1;
      }
    }
    cout << (cnt == 1 ? idx : -1) << endl;
  }
  return 0;
}

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

int main() {
  while(1) {
    int n,m;
    cin >> n;
    if(n == 0) break;

    vector <int> sta[101];
    for(int i=1;i<=n;i++) {
      cin >> m;
      sta[i].resize(m);
      for(int j=0;j<m;j++) cin >> sta[i][j];
      sort(sta[i].begin(),sta[i].end());
    }

    int k;
    cin >> k;
    vector <int> ot;
    ot.resize(k);
    for(int i=0;i<k;i++) cin >> ot[i];
    sort(ot.begin(),ot.end());

    int ans = 0;
    for(int i=1;i<=n;i++) {
      int cnt = 0;
      for(int j=0;j<sta[i].size();j++){
	if(sta[i][j] == ot[cnt]) cnt++;
	if(cnt == k && ans != 0) {
	  ans = -1;
	  break;
	}
	if(cnt == k) {
	  ans = i;
	  break;
	}
      }
      if(ans == -1) break;
    }
    if(ans == 0) ans = -1;
    cout << ans <<endl;
  }

  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>	
#include<functional>

using namespace std;

namespace MyLib {
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long
}

using namespace MyLib;

int main() {
	int n;
	int m[101];
	int p[101][101];
	int buf;
	while (cin >> n, n) {
		REP(i, 101)
			fill(p[i], p[i] + 101, 0);
		REP(i, n) {
			cin >> m[i + 1];
			REP(j, m[i + 1]) {
				cin >> buf;
				p[i + 1][buf] = 1;
			}
		}
		int k;
		cin >> k;
		int x = -1;
		REP(i, k) {
			cin >> buf;
			p[0][buf] = 1;
		}
		REP(i, n)
			REP(j, n) {
			if (p[i + 1][j + 1] == 0 && p[0][j + 1] == 1)
				break;
			if (j == n - 1)
				if(x==-1)x = i + 1;
				else x = -2;
		}

		if (x == -2)
			x = -1;


		cout << x << endl;



	}
}

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


int main(){
	
	int N;
	while(cin>>N,N){
		int data[101][101]={0};
		for(int i=1,j;i<=N;i++){
			cin>>j;
			for(int k=0,l;k<j;k++){
				cin>>l;
				data[i][l]=1;
			}
		}
		
		int r;
		cin>>r;
		for(int i=0,k;i<r;i++){
			cin>>k;
			for(int j=1;j<=N;j++){
				if(data[j][k]==0)data[j][0]=1;
			}
		}
		int ans=0;
		for(int i=1;i<=N;i++){
			if(data[i][0]==0){
				if(ans==0)ans=i;
				else ans=-1;
			}
		}
		if(ans==0)ans=-1;
		cout<<ans<<endl;
	}
	
	return 0;
}

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

using namespace std;

int main() {
	while (true) {
		int N;
		cin >> N;
		if (N == 0) {
			break;
		}
		
		vector<int> member[N];
		for (int i = 0; i < N; i++) {
			int M;
			cin >> M;
			for (int j = 0; j < M; j++) {
				int p;
				cin >> p;
				member[i].push_back(p);
			}
			sort(member[i].begin(), member[i].end());
		}
		vector<int> leak;
		int K;
		cin >> K;
		for (int i = 0; i < K; i++) {
			int l;
			cin >> l;
			leak.push_back(l);
		}
		sort(leak.begin(), leak.end());
		
		int ans = -1;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < (int)leak.size(); j++) {
				if (!(binary_search(member[i].begin(), member[i].end(), leak[j]))) {
					goto nextmember;
				}
			}
			if (ans != -1) {
				ans = -1;
				goto end;
			} else {
				ans = i + 1;
			}
		nextmember:
			int a;
		}
	end:
		cout << ans << endl;
	}
	
	return 0;
}

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

int main(){

  int N;
  for(;;){
    int p[100][100]={{0}};
    cin >> N;
    if(!N)break;
    for(int i=0;i<N;++i){
      int M;
      cin >> M;
      int pnum;
      for(int j=0;j<M;++j){
	cin >> pnum;
	p[i][pnum-1]=1;
      }
    }

    int K;
    cin >> K;
    int l[100];
    for(int i=0;i<K;++i){
      cin >> l[i];
    }

    int lnum[100]={0};
    int criminal;
    for(int i=0;i<K;++i)
      for(int j=0;j<N;j++)
	if(p[j][l[i]-1]){
	  int tmp=1;
	  for(int k=0;k<K;k++){
	    lnum[k] += p[j][l[k]-1];
	    tmp *= p[j][l[k]-1];
	    p[j][l[k]-1] = 0;
	  }
	  if(tmp)
	    criminal = j+1;
	}
    int is1 = 0;
    for(int i=0;i<K;++i){
      if(lnum[i]==0){
	criminal = -1;
	break;
      }
      if(lnum[i]==1){
	is1 = 1;
	break;
      }
    }

    if(!is1) criminal = -1;

    cout << criminal << endl;
  }
}