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 <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;


int main() {
	int n;
	while(cin >> n, n) {
		int f[101][101] = {};
		FOR(i, 1, n+1) {
			int m; cin >> m;
			FOR(j, 1, m+1)
				cin >> f[i][j];
			sort(f[1], f[1]+m, less<int>());
		}
		int k; cin >> k;
		int l[k], cnt, ans = 0;
		REP(i, k)
			cin >> l[i];
		sort(l, l+k, less<int>());
		FOR(i, 1, n+1) {
			cnt = 0;
			FOR(j, 1, n+1) {
				if(f[i][j] == l[cnt])
					cnt++; 
				if(cnt == k) {
					if(!ans) ans = i;
					else ans = -1;
					break;
				}
			}
		}
		if(ans == 0) ans = -1;
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;

int main()
{
  int n,m,k;
  int i,j;
  int p[105][105]={};
  int l[105]={};
  int a;

  while(1){
    cin>>n;
    if(n==0)break;
    rep(i,n){
      cin>>m;
      rep(j,m){
	cin>>a;
	p[i][a]++;
      }
    }
    cin>>k;
    rep(i,k){
      cin>>a;
      l[a]++;
    }
 
    queue<int> q;

    rep(i,n){
      bool ans=true;
      rep(j,105)
	if(l[j]>p[i][j])
	  ans=false;
      if(ans)q.push(i);
    }
    if(q.size()==1)
      cout<<q.front()+1<<endl;
    else
      cout<<"-1"<<endl;
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		set<int>s[101];
		for(int i=0;i++<n;)
		{
			int m;cin>>m;
			for(;m--;)
			{
				int a;cin>>a;s[i].insert(a);
			}
		}
		int m;cin>>m;set<int>t;
		for(;m--;)
		{
			int a;cin>>a;t.insert(a);
		}
		int cnt=0,I=-1;
		for(int i=0;i++<n;)
		{
			int f=1;
			for(int it:t)
			{
				f&=s[i].find(it)!=s[i].end();
			}
			if(f)
			{
				cnt++;
				if(cnt==1)I=i;
				else I=-1;
			}
		}
		cout<<I<<" "<<endl;
	}
}

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

template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}

void solve(int n){
	vector<int> v[n], w;
	for(int i=0; i<n; ++i){
		int m;
		cin >> m;
		readVector(m, v[i]);
		sort(v[i].begin(), v[i].end());
	}
	int k;
	cin >> k;
	readVector(k, w);
	sort(w.begin(), w.end());
	int res = -1;
	for(int i=0; i<n; ++i){
		bool f = true;
		int t = 0;
		for(int j=0; j<k; ++j){
//			cout << i << " " << j << " " << t << "\n";
			while(t < v[i].size() && v[i][t] != w[j]) ++t;
			if(t == v[i].size()){
//				cout << i << "\n";
				f = false;
				break;
			}
			++t;
		}
		if(f){
			if(res != -1){
				res = -1;
//				cout << i << " " << res << "\n";
				break;
			}else{
				res = i+1;
			}
		}
//		cout << i << " " << res << "\n";
	}
	cout << res << "\n";
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}

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

using namespace std;

signed main(){

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

      int data[N][N];
      fill((int*)data, (int*)data+N*N, 0);
      for(int i=0; i<N; i++){
         int M;
         cin>> M;
         for(int j=0; j<M; j++){
            int p;
            cin>> p;
            data[i][p-1]=1;
         }
      }
      int K;
      cin>> K;
      int l[K];
      for(int i=0; i<K; i++){
         cin>> l[i];
         l[i]--;
      }
      int tada[N]={0};
      for(int i=0; i<K; i++){
         tada[l[i]]=1;
      }

      vector<int> ans;
      for(int i=0; i<N; i++){
         int f=1;
         for(int j=0; j<N; j++){
            f&=(data[i][j]==tada[j]||data[i][j]);
         }
         if(f) ans.push_back(i+1);
      }

      if(ans.size()!=1){
         cout<< -1<< endl;
      }else{
         cout<< ans[0]<< endl;
      }

   }

   return 0;
}