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 <algorithm>

using namespace std;

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

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

		vector< vector<int> > data;

		//データ取得
		for(int i = 0; i < N; i++) {
			int m;
			cin >> m;		
			vector<int> v;
			for(int j = 0; j < m; j++) {
				int p;
				cin >> p;
				v.push_back(p);
			}
			data.push_back(v);
		}

		vector< int > w;
		int K;
		cin >> K;
		for(int i = 0; i < K; i++) {
			int l;
			cin >> l;
			w.push_back( l );
		}

		//調べる
		/*
			wの各要素に一致するデータの個数を調べる
		*/
		vector< vector<int> > suspect;
		for(int i = 0; i < w.size(); i++) {
			vector<int> v;
			for(int j = 0; j < data.size(); j++) {
				for( int k = 0; k < data.at( j ).size(); k++ ) {
					if( w.at( i ) == data.at( j ).at( k ) ) v.push_back( i );
				}
			}
			suspect.push_back( v );
		//	cout << v.size() << " ";
		}
	//	cout << endl;

		int flg = true;
		int cnt = 0;
		int indx = -1;
		for(int i = 0; i < suspect.size(); i++) {
			if( suspect.at(i).size() == 1 ) {
				cnt ++;
				if( indx != -1 && indx != suspect.at(i).at(0) ) flg = false;
				indx = suspect.at(i).at(0);
				flg = true;
			}
		}
		if( cnt == 0 ) flg = false;

		if( flg ) {
			cout << suspect.at(indx).at(0) << endl;
		} else {
			cout << -1 << endl;
		}

	}

	//while(1){}

	return 0;
}

C++: #include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	
	int n;
	int a[100]={};
	
	while( cin >> n && n!=0)
	{
		REP(i,n)
		{
			int k;
			cin >> k;
			REP(j,k)
			{
				int l;
				cin >> l;
				a[l-1] ++;
			}
		}

		int ans(0);
		
		int k;
		cin >> k;
		REP(i,k)
		{
			int l;
			cin >> l;
			if(a[l-1]==1){	ans++;	}
		}
		
		if(ans!=0)
		cout << ans << endl;
		else cout << -1 << endl;
		
	}
	return 0 ;
}

C++: #include <iostream>
#include <vector>
using namespace std;
struct vec{
	vector<int> ve;
};

int main(){
	int n,m,k,a,l,count,num;
	bool flag;
	vector<vec> vv;
	vector<int> vl;
	vec v;
	while(1){
		cin >> n;
		if(n == 0)break;
			vv.clear();
			count = 0;
		for(int i = 0;i < n;i++){
			cin >> m;
			v.ve.clear();
			for(int j = 0;j < m;j++){
				cin >> a;
				v.ve.push_back(a);
			}
			if(m != 0)vv.push_back(v);
			else if(m == 0){
				v.ve.push_back(-1);
				vv.push_back(v);
			}
		}
		cin >> l;
		vl.clear();
		for(int i = 0;i < l;i++){
			cin >> a;
			vl.push_back(a);
		}
		for(int i = 0;i < vv.size();i++){
			for(int j = 0;j < vl.size();j++){
			flag = false;
				for(int k = 0;k < vv[i].ve.size();k++){
					if(vl[j] == vv[i].ve[k]){
						flag = true;
						break;
					}
				}
			if(flag == false)break;
			}
			if(flag == true){
				count++;
				num = i;
			}
		}
		if(count == 1)cout << num+1 <<endl;
		else cout << -1 <<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int a,b;
  int r[100];
  int s[100];
  int p[100][100];
  int sum;
  bool c=false;
  while(1){
    c=false;
    for(int i=0;i<100;i++){
      for(int j=0;j<100;j++){
	p[i][j]=0;
      }
    }
    cin>>N;
    if(N==0) break;
    for(int i=0;i<N;i++){
      cin>>a;
      if(a==0) continue;
      for(int j=0;j<a;j++){
	cin>>b;
	p[i][b-1]=1;
      }
    }
    for(int i=0;i<N;i++){
      sum=0;
      for(int j=0;j<N;j++){
	sum+=p[j][i];
      }
      r[i]=sum;
    }
    cin>>a;
    for(int i=0;i<a;i++){
      cin>>b;
      if(r[b-1]==1){
	for(int j=0;j<N;j++){
	  if(p[j][b-1]==1){
	    cout<<j+1<<endl;
	    c=true;
	    break;
	  }
	}
      }
    }
    if(c==false) cout<<-1<<endl;
    /*for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
	cout<<p[i][j];
      }
      cout<<endl;
      }*/
    }
  return 0;
}

C++: #include <stdio.h>

int main(){
  
  int mm,kk,n;
  int m[105][105];
  
  int k[105];
  int i,j,rin,ans1,ans2,p,q;
  
  //  scanf("%d",&n);
  p=0;  q=0;
  while(1){  
    p++;
    ans1=0;
    for(i=0;i<105;i++){
      for(j=0;j<105;j++){
	m[i][j]=0;
      }
    }
    
    for(i=0;i<105;i++)
      k[i]=0;

    ans1=0;//初期化
    scanf("%d",&n);
    if(n==0){
      
      return 0;
    }//終了
    
    
  
    for(i=1;i<n+1;i++){
      scanf("%d",&mm);
  
      for(j=1;j<mm+1;j++){
	scanf("%d",&rin);

	m[i][rin]=1;
      }
    }
  
    scanf("%d",&rin);
    kk=rin;
    for(i=1;i<kk+1;i++){
      scanf("%d",&rin);
      k[rin]=1;}
    
    for(i=1;i<n+1;i++){
      for(j=1;m[i][j]>=k[j]&&j<n+1;j++);
  
      if(j==n+1)
	{  /*printf("--------\n");
	  for(j=1;j<n+1;j++) printf("%d ",m[i][j]);
	  printf("\n");
	  for(j=1;j<n+1;j++) printf("%d ",k[j]);
	  printf("\n--------\n");*/
	  ans1++;
	  ans2=i;
	}
    }

    /* for(i=1;i<n+1;i++){
        printf("\n");
      for(j=1;j<n+1;j++)
		printf("  %d",m[i][j]);
		}*/
    if(ans1==1) printf(" %d\n",ans2);
      else printf(" -1\n");
    
  }
}