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) {
	int num = 0;
	cin >> num;
	while (num != 0) {
		vector<vector<int>> member(100);
		vector<int> data;
		int a = 0, b = 0;
		bool check[100];
		int betrayer = -1;
		bool isthere = false;
		for (int i = 0; i < num; i++) {
			cin >> a;
			member[i].push_back(a);
			for (int j = 0; j < a; j++) {
				cin >> b;
				member[i].push_back(b);
			}
			sort(member[i].begin()+1, member[i].end());
		}
		int pnum = 0;
		cin >> pnum;
		data.push_back(pnum);
		for (int i = 0; i < pnum; i++) {
			cin >> b;
			data.push_back(b);
		}
		sort(data.begin()+1, data.end());
		for (int i = 0; i < num; i++) {
			int chck = 1;
			for (int k = 0; k < 100; k++) {
				check[k] = false;
			}
			for (int j = 1; j <= member[i][0]; j++) {
				if(chck <= data[0]){
				if (data[chck] == member[i][j]) {
					check[chck] = true;
					chck++;
				  }
				}
			}
			if (check[data[0]]) {
				if (!isthere) {
					betrayer = i + 1;
					isthere = true;
				}
				else {
					betrayer = -1;
				}
			}


		}
		cout << betrayer << endl;
		cin >> num;
	}
}

C++: ///
// File:  2399.cpp
// Author: ymiyamoto
//
// Created on Mon Nov 13 21:04:52 2017
//

#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

int32_t main()
{
  while (true) {
    uint32_t N;
    cin >> N;

    if (N == 0) break;

    array<vector<uint32_t>, 101> mem;

    for (uint32_t i = 1; i <= N; i++) {
      uint32_t n;
      cin >> n;
      for (uint32_t j = 0; j < n; j++) {
        uint32_t m;
        cin >> m;
        mem[i].push_back(m);
      }
      sort(mem[i].begin(), mem[i].end());
    }

    vector<uint32_t> dis;
    uint32_t n;
    cin >> n;
    for (uint32_t i = 0; i < n; i++) {
      uint32_t m;
      cin >> m;
      dis.push_back(m);
    }
    sort(dis.begin(), dis.end());

    int32_t m = -1;
    for (uint32_t i = 1; i <= N; i++) {
      uint32_t all_found = true;
      for (uint32_t j = 0; j < dis.size(); j++) {
        uint32_t found = false;
        for (uint32_t k = 0; k < mem[i].size(); k++) {
          if (dis[j] == mem[i][k]) {
            found = true;
          }
        }
        all_found &= found;
      }

      if (all_found) {
        if (m != -1) {
          m = -1;
          break;
        } else {
          m = i;
        }
      }
    }
    cout << m << endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;


int main(){
	while(1){
		int n,p[101][101],l,i,j,k,me[101],m,a,flg=0;
		cin>>n;
		if(n==0)break;
		for(i=0;i<101;i++){
			for(j=0;j<101;j++){
				if(j!=0){
					p[i][j]=0;//初期化
				}else{
					p[i][j]=1;
				}
			}
		}
		for(i=1;i<=n;i++){
			cin>>m;
			for(j=0;j<m;j++){
				cin>>a;
				p[i][a]=1;
			}
		}
		cin>>k;
		for(i=0;i<k;i++){
			cin>>me[i];
		}
		for(i=1;i<=n;i++){
			for(j=0;j<k;j++){
				if(p[i][me[j]]==0){
					p[i][0]=0;
				}
			}
		}
		flg=0;a=-1;
		for(i=1;i<=n;i++){
			if(p[i][0]==1){
				if(flg==0){
					flg=1;a=i;
				}else{
					a=-1;flg=2;
					break;
				}
			}
		}
		cout<<a<<endl;
	}
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=2005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        
        int ans=-1,cnt=0;
        
        vector<vector<int>> A(N);
        
        for(int i=0;i<N;i++){
            int M;cin>>M;
            A[i].assign(M,0);
            for(int j=0;j<M;j++){
                cin>>A[i][j];
            }
            sort(all(A[i]));
        }
        int K;cin>>K;
        vector<int> B(K);
        for(int i=0;i<K;i++) cin>>B[i];
        
        sort(all(B));
        
        for(int i=0;i<N;i++){
            bool ok=true;
            for(int j=0;j<K;j++){
                if(!binary_search(all(A[i]),B[j])) ok=false;
            }
            if(ok){
                ans=i+1;
                cnt++;
            }
        }
        
        if(cnt>=2) ans=-1;
        
        cout<<ans<<endl;
        
    }
    
}

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

using namespace std;

int n, k;
bool know[256][256];
bool leak[256];

int main(){

	while(cin>>n, n){
		
		memset(know, 0, sizeof(know));
		memset(leak, 0, sizeof(leak));

		for(int i=0; i<n; ++i){
		
			int m;
			cin>>m;
			
			for(int j=0; j<m; ++j){
				
				int p;
				cin>>p;
				know[i][--p] = true;
			}
		}

		cin>>k;

		for(int i=0; i<k; ++i){
			
			int l;
			cin>>l;
			leak[--l]=true;
		}

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

			bool f = true;

			for(int j=0; j<n; ++j){
				
				if( i != j && !know[i][j] && leak[j] ){
					f = false;
					break;
				}
			}

			if(f){
				if(spy==-1){
					spy = i;
				}
				else{
					spy = -2;
				}
			}
		}

		cout << (spy>=0?++spy:-1) << endl;
	}

	return 0;
}