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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define _D(p) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p)<<std::endl;
#define _D2(p,q) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p) << ", " #q " = "<<(q)<<std::endl;
#define _DN(v) std::cout<<"L"<<__LINE__<<" : " #v " = ["; rep(i,(v).size()) {std::cout<<v[i]<<(i==v.size()-1?"":", ");}std::cout<<"]"<<std::endl;
#define _DNN(v) std::cout<<"L"<<__LINE__<<" : " #v " = [" << std::endl; rep(i,(v).size()) {std::cout<<"	[";rep(j,(v)[0].size()){std::cout<<v[i][j]<<(j==v[0].size()-1?"":", ");}std::cout<<"],"<<std::endl;}std::cout<<"]"<<std::endl;
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(int argc, char const *argv[]) {
	while(1) {

		int N;
		cin >> N;
		if (N == 0) break;

		int P[200][200] = {{0}};
		int I[200] = {0};
		for (int i = 0; i < N; ++i) {
			int M;
			cin >> M;
			for (int j = 0; j < M; ++j) {
				int temp;
				cin >> temp;
				temp--;
				P[i][temp] = 1;
			}
		}
		int K;
		cin >> K;
		for (int i = 0; i < N; ++i) {
			I[i] = 0;
		}
		for (int i = 0; i < K; ++i) {
			int temp;
			cin >> temp;
			temp--;
			I[temp] = 1;
		}

		vector<int> ans;

		for (int i = 0; i < N; ++i) {
			bool flag = true;
			for (int j = 0; j < N; ++j) {
				if (I[j] == 1 && P[i][j] == 0) {
					flag = false;
					break;
				}
			}
			if (flag) {
				ans.push_back(i);
			}
		}
		if (ans.size() == 1) {
			cout << ans[0] + 1<< endl;
		} else {
			cout << "-1" << endl;
		}


	}

	return 0;
}

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

int main(){
  while(1){
    int p[N][N]={},l,n,m,a,ans=-1,fl[N]={},cnt=0;
  cin>>n;
  if(n==0) break;
  for(int i=1;i<=n;i++){
    cin>>m;
    for(int j=0;j<m;j++){
      cin>>l;
    p[i][l]=1;
    }
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>a;
    for(int j=1;j<=n;j++){
      if(p[j][a]==0) fl[j]=0;
      if(p[j][a]==1 && i==0) fl[j]=1;
      if(p[j][a]==1 && i>0 && fl[j]==1) fl[j]=1;
    }
  }
  for(int i=1;i<=n;i++)
    if(fl[i]==1){
      ans=i;
      cnt++;
    }
  
  if(cnt!=1) ans=-1;
       cout<<ans<<endl;
  }
  return 0;
}

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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n;
	
	while (cin >> n, n) {
		bool f[101][101] = {false};
		rep(i, n) {
			int m = in();
			rep(j, m) {
				f[i][in()] = true;
			}
		}

		vi a, l;
		
		int k = in();
		rep(i, k) l.pb(in());

		rep(i, n) {
			bool beet = true;
			rep(j, l.size()) {
				if (!f[i][l[j]]) beet = false;
			}
			if (beet) a.pb(i + 1);
		}

		cout << (a.size() == 1 ? a[0] : -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;
	}
}