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 <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int N;

bool check(set<int> &v, set<int> &k){
  for(set<int>::iterator it = k.begin(); it != k.end(); ++it) if(v.find((*it)) == v.end()) return false;
  return true;
}

int calc(vector< set<int> > &v, set<int> &k){
  int ret = -1;
  REP(i, N){
    bool ans = check(v[i], k);
    if(ans){
      if(ret == -1) ret = i + 1;
      else return -1;
    }
  }
  return ret;
}

int main() {
  while(cin >>N && N){
    vector< set<int> > v(N);
    set<int> k;
    REP(i, N){
      int M; cin >>M;
      REP(j, M){
        int tmp; cin >>tmp;
        v[i].insert(tmp);
      }
    }
    int M; cin >>M;
    REP(i, M){
      int tmp; cin >>tmp;
      k.insert(tmp);
    }
    cout <<calc(v, k) <<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int n;
	while (scanf("%d", &n), n) {
		vector<int>E[110];
		rep(i, n) {
			int m; scanf("%d", &m);
			rep(j, m) {
				int p; scanf("%d", &p);
				E[--p].push_back(i);
			}
		}
		vector<int>ans(n);
		iota(ans.begin(), ans.end(), 0);
		int k; scanf("%d", &k);
		rep(i, k) {
			int l; scanf("%d", &l); l--;
			rep(j, ans.size()) {
				if (find(E[l].begin(), E[l].end(), ans[j]) == E[l].end()) {
					ans.erase(ans.begin() + j); j--;
				}
			}
		}
		if (ans.size() != 1)puts("-1");
		else printf("%d\n", ans[0] + 1);
	}
}

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

int n;
int m;
int k;
int ls[200];
set<int> ps[200];

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;
  
    for (int i=0; i<n; i++) {
      scanf("%d", &m);
      ps[i].clear();
      for (int j=0; j<m; j++) {
        int p;
        scanf("%d", &p);
        ps[i].insert(p);
      }
    }
  
    scanf("%d", &k);
    for (int i=0; i<k; i++) {
      scanf("%d", &ls[i]);
    }
  
    int ans = -1;
    for (int i=0; i<n; i++) {
      bool possible = true;
      for (int j=0; j<k; j++) {
        if (!ps[i].count(ls[j])) {
          possible = false;
          break;
        }
      }
  
      if (possible) {
        if (ans == -1) ans = i+1;
        else {
          puts("-1");
          ans = -2;
          break;
        }
      }
    }
  
    if (ans != -2) printf("%d\n", ans);
  }
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int n;
    while(cin>>n,n){
        vvi v(100,vi()); vi u(100,0);
        rep(i,n){
            int temp; cin>>temp;
            rep(j,temp){int a;cin>>a; v[a].push_back(i);};
        }
        int temp; cin>>temp;
        rep(i,temp)cin>>u[i];
        bool check = false; int ans = 0;
            int cnt = 0;
            rep(i,temp){
                if(v[u[i]].empty()) break;
                cnt++;
                if(v[u[i]].size() == 1){check = true;ans = v[u[i]].back();}
                }
        if(cnt != temp) check = false;
        if(check) cout << ans+ 1<< endl;
        else cout << -1 << endl;
    }
}

C++: #include<iostream>
#define N 100
using namespace std;

int main(){
  while(1){
  int n,m,pr;
  int p[N]={};
  cin>>n;
  if(n==0) break;
  for(int i=1;i<=n;i++){
    cin>>m;
    for(int j=0;j<m;j++){
      cin>>pr;
      if(p[pr]==0)
    p[pr]=i;
      else 
	p[pr]=-1;
    }
  }
    cin>>m;
    int ans=0,f=0;
    for(int i=0;i<m;i++){
      cin>>pr;
      cout<<p[pr]<<endl;
      if(p[pr]>0 && f==0 &&(ans==0 || ans==p[pr])) ans=p[pr];
        }
    if(ans==0) ans=-1;
    cout<<ans<<endl;
  }
  return 0;

}