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<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int solve(int N){
    set<int> st[N];
    rep(i,0,N){
        int k;
        cin >> k;
        rep(j,0,k){
            int a;
            cin >> a;
            st[i].insert(a);
        }
    }
    int ans = -1;
    int M;
    cin >> M;
    vector<int> V(M);
    rep(i,0,M)cin >> V[i];
    rep(i,0,N){
        bool ok = 1;
        rep(j,0,M){
            if(st[i].count(V[j]))continue;
            ok = 0;
            break;
        }
        if(!ok)continue;
        if(ans != -1)return -1;
        ans = i + 1;
    }
    return ans;
}
main(){
    int N;
    cin >> N;
    while(N){
        cout << solve(N) << endl;
        cin >> N;
    }
}

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

using namespace std;


int main(){
	int count;
	set <int> data[1001];
	while (1){
		cin >> count;
		if (!count)break;
		for (size_t i = 0; i < count; i++)
		{
			int count2;
			cin >> count2;
			for (size_t j = 0; j < count2; j++)
			{
				int data2;
				cin >> data2;
				data[i].insert(data2);
			}
			data[i].insert(1000);
		}
		int count3;
		cin >> count3;
		int a[1001];
		for (size_t i = 0; i < count3; i++)
		{
			int data3;
			cin >> data3;
			a[i] = data3;
		}
		int whois=-1;
		int count4 = 0;
		for (size_t i = 0; i < count; i++)
		{
			bool f = 1;
			for (size_t j = 0; j < count3; j++)
			{
				if (data[i].find(a[j]) == data[i].end()){
					//cout << a[j] << endl;
					f = 0;
					break;
				}
			}
			if (f){
				count4++;
				whois = i + 1;
			}
		}
		if (count4 == 1){
			cout << whois << endl;
		}
		else{
			cout << -1 << endl;
		}
		//cout << count4 << whois << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
typedef __int64 ll;


int main() {
	int n;
	while(cin >> n, n) {
		vector<vector<int> > ms(n, vector<int>());
		for(int i = 0; i < n; i++) {
			int m;
			cin >> m;
			for(int j = 0; j < m; j++) {
				int mss;
				cin >> mss;
				mss--;
				ms[i].push_back(mss);
			}
		}
		int k;
		cin >> k;
		vector<int> led(n);
		for(int i = 0; i < k; i++) {
			int j;
			cin >> j;
			j--;
			led[j] = 1;
		}
		bool summable = true;
		// fill one
		int kouho = -1;
		for(int i = 0; i < n; i++) {
			int count = 0;
			for(int j = 0; j < ms[i].size(); j++) {
				if(led[ms[i][j]]) count++;
			}
			if (count == k) {
				if (kouho != -1) {
					cout << -1 << endl;
					goto end_loop;
				}
				kouho = i;
			}
		}
		// fill some
		for(int i = 0; i < n; i++) {
			if (i == kouho) continue;
			int count = 0;
			for(int j = 0; j < ms[i].size(); j++) {
				if(led[ms[i][j]]) count++;
			}
			if (count == ms[i].size()) {
				for(int j = 0; j < ms[i].size(); j++) {
					led[ms[i][j]] = 2;
					//cout << "sum" << ms[i][j] << endl;
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			if (led[i] == 1) {
				summable = false;
				break;
			}
		}
		if (summable || kouho == -1) {
			cout << -1 << endl;
		}
		else {
			cout << kouho+1 << endl;
		}
		
		end_loop: {}
	}
	
	return 0;
}

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

#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}
using namespace std;
int ans[100000],check[100000];
int main(){
  list<int> l;
  list<int>::iterator it;
  it = l.end();
  int n;
  cin>>n;
  lp(i,n){
    int a,b;
    cin>>a;
    if(a==0){
      cin>>b;
      l.insert(it, b);
      it++;
    }
    if(a==1){
      cin>>b;
      it = l.begin()+b;
    }
    if(a==2){
      l.erase(it);
      if(it--) 1;
      else it= l.end();
    }
  }
  it=l.begin();
  while(it!=l.end()){
    cout<<*it<<endl;
    it++;
  }
      
    
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		int m,p[n][n]={},shitteru;
		for(int i=0;i<n;i++){
			cin>>m;
			for(int j=0;j<m;j++){
				cin>>shitteru;
				p[i][shitteru]=1;
			}
		}
		int k;
		cin>>k;
		int l[k];
		for(int i=0;i<k;i++){
			cin>>l[i];
		}
		int hannin=-1;
		for(int i=0;i<n;i++){
			int flg=1;
			for(int j=0;j<k;j++){
				if(p[i][l[j]]==0){
					flg=0;
					break;
				}
			}
			if(flg==1&&hannin==-1){
				hannin=i+1;
			}
			else if(flg==1&&hannin>-1){
				hannin=-1;
				break;
			}
		}
		cout<<hannin<<endl;
	}
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,m;
  while(cin >>n,n){
    int field[101][10] = {0},ans[10] = {0};
    for(int i=1,x; i<=n; i++){
      cin >>x;
      for(int j=0,r; j<x; j++){
	cin >>r;
	field[i][r/10] |= 1<<(r%10);
      }
    }
    cin >>m;
    for(int i=0,q; i<m; i++){
      cin >>q;
      ans[q/10] |= 1<<(q%10);
    }
    int x = 0;
    for(int i=1,j; i<=n; i++){
      for(j=0; j<10; j++){
	if((ans[j]&field[i][j]) != ans[j]){break;}
      }
      if(j == 10){
	if(!x){x = i;}
	else{x = -1;break;}
      }
    }
    if(!x){x = -1;}
    cout <<x<<endl;
  }
  return 0;
}