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 <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iterator>
#include <sstream>

using namespace std;

int N;
bool p[100][100];

int main()
{
	while(cin>>N,N){
		memset(p,0,sizeof(p));
		for (int i = 0; i < N; i++){
			int m; cin>>m;
			for (int j = 0; j < m; j++){
				int x; cin>>x;
				x--;
				p[i][x] = true;
			}
			//p[i][i] = true;
		}
		int k; cin>>k;
		vector<int> l(k);
		for (int i = 0; i < k; i++){ cin>>l[i]; l[i]--;}

		int ans = -1;
		for (int i = 0; i < N; i++){
			int j;
			for (j= 0; j< k; j++){
				if(!p[i][l[j]]) break;
			}
			if(j == k){
				if(ans == -1){
					ans = i + 1;
				} else {
					ans = -1; break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  bool graph[100][100];
  bool rouei[100];
  while(cin >> n, n){
    int num = -2;
    for(int i = 0; i < 100; ++i){
      rouei[i] = false;
      for( int j = 0; j < 100; ++j)
        graph[i][j] = false;
    }
    for(int i = 0; i < n; ++i){
      int m; cin >> m;
      for(int j = 0; j < m; ++j){
        int tmp; cin >> tmp;
        graph[i][tmp] = true;
      }
    }
    int k; cin >> k;
    for(int i = 0; i < k; ++i){
      int tmp; cin >> tmp;
      rouei[tmp] = true;
    }
    for(int i = 0; i < 100 ; ++i){
      bool flag = true;
      for( int j = 0; j < 100 && flag; ++j){
        if(rouei[j]){
          if(!graph[i][j]) flag = false;
        }
      }
      if(flag && num == -2)
        num = i;
      else if(num != -2 && flag)
        num = -1;
    }
    if(num == -2) num = -1;
    else if(num >= 0) num++;
    cout << num << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
  int N;
  while(cin >> N, N){
    int info[100][100];
    int M[100];
    for(int i = 0; i < N; i++){
      cin >> M[i];
      for(int j = 0; j < M[i]; j++) cin >> info[i][j];
      sort(info[i], info[i] + M[i]);
    }
    int K;
    cin >> K;
    int leak[100];
    for(int i = 0; i < K; i++) cin >> leak[i];
    sort(leak, leak + K);
    int ans = -1;
    for(int i = 0; i < N; i++){
      if(M[i] < K) continue;
      int cnt = 0;
      for(int j = 0; j < K; j++){
	for(int k = 0; k < M[i]; k++){
	  if(leak[j] == info[i][k]){
	    cnt++;
	    break;
	  }
	}
      }
      if(cnt == K){
	if(ans != -1){
	  ans = -1;
	  break;
	} else {
	  ans = i + 1;
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set;
using std::queue;
using std::priority_queue;
using std::stack;

typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef vector<string> VS;
typedef pair<int, int> PII;

int main(void) {
    int n;
    while (cin >> n) {
        if (n == 0) {
            break;
        }

        VII table(n);
        int number;
        int temp;
        VI ans;

        for (int i = 0; i < n; i++) {
            cin >> number;
            if (number == 0) {
                continue;
            }
            for (int j = 0; j < number; j++) {
                cin >> temp;
                table[i].push_back(temp);
            }
        }
        for (int j = 0; j < n; j++) {
            sort(table[j].begin(), table[j].end());
        }
        cin >> number;
        for (int j = 0; j < number; j++) {
            cin >> temp;
            ans.push_back(temp);
        }
        sort(ans.begin(), ans.end());


        int count = 0;
        int output;
        for (int i = 0; i < n; i++) {
            /*
               for (int m = 0; m < table[i].size(); m++) {
               cout << table[i][m] <<endl;
               }
               cout << endl;
               if (table[i].size() < ans.size()) {
               continue; 
               }
             */

            int j = 0;
            for (int k = 0; k < table[i].size(); k++) {
                //cout << "J = " << j << endl;
                //cout << table[i][k] << " " << ans[j] << endl;
                if (table[i][k] == ans[j]) {
                    j++;
                }
                if (j == ans.size()) {
                //cout << i << j << k << count << endl;
                    count++;
                    output = i + 1;
                    break;
                }
            }
        }
        if (count != 1) {
            //cout << "C = " << count << endl;
            cout << -1 << endl;
        } else {
            //cout << "C = " << count << endl;
            cout << output << endl;
        }
    }

    return 0;
}