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"
#include <random>
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;
 
 
void reader(int &a){scanf("%d",&a);}
void reader(double &a){scanf("%lf",&a);}
void reader(char a[]){scanf("%s",a);}
void reader(ll &a){scanf("%lld",&a);}
void reader(ull &a){scanf("%llu",&a);}
// void reader(string& a){cin >> a;};
template<class T,class U> void reader(T& t,U& u){reader(t); reader(u);}
template<class T,class U,class V> void reader(T& t,U& u,V& v){reader(t); reader(u); reader(v);}
 
void writer(int a,char c) {printf("%d",a); putchar(c);}
void writer(ll a,char c) {printf("%lld",a); putchar(c);}
void writer(double a,char c) {printf("%.20lf",a); putchar(c);}
void writer(char a[]) {printf("%s",a);};
void writer(char a[],char c) {printf("%s",a);putchar(c);};
void writer(char a,char c) {putchar(a); putchar(c);};
template<class T>void writerLn(T t){writer(t,'\n');}
template<class T,class U>void writerLn(T t,U u){writer(t,' ');writer(u,'\n');}
template<class T,class U,class V> void writerLn(T t,U u,V v){writer(t,' ');writer(u,' ');writer(v,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
template<class T> void writerVec(vector<T> x){int n=x.size();int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
 
vector<std::string> split(const std::string &str, char sep){std::vector<std::string> v;std::stringstream ss(str);std::string buffer;while(std::getline(ss,buffer,sep)){v.push_back(buffer);}return v;}
 
// #define int ll
bool test = 1;
int dx[] = { 0,0,1,-1 };
int dy[] = { 1,-1,0,0 };

//..................
ull mod = (int)1e9 + 7;
signed main(){
  int i,j,k,l;
  string s;
  while(1) {
	int N,K;
	vector<int> connect[100];
	int l[100];
	cin >> N;
	if(N == 0) return 0;
	rep(i,N) {
	  int M;
	  cin >> M;
	  rep(j,M) {
		int p;
		cin >> p;
		connect[i].push_back(p);
	  }
	}
	cin >> K;
	rep(i,K) cin >> l[i];
	int ans = -1;
	rep(i,N) {
	  bool correct = true;
	  rep(j,K) {
		rep(k,connect[i].size()) {
		  if(connect[i][k] == l[j]) break;
		}
		if(k == connect[i].size()) correct = false;
	  }
	  if(ans != -1 && correct) {
		ans = -1;
		break;
	  }
	  else if(ans == -1 && correct) ans = i;
	}
	if(ans == -1) cout << -1 << endl;
	else cout << ans+1 << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n,a,b;

  while(cin >> n ,n){
    vector<int> v[n];
    for(int i = 0 ; i < n ; i++){
      cin >> a;
      for(int j = 0 ; j < a ; j++){
	cin >> b;
	v[i].push_back(b);
      }
    }

    int check[101] = {0};
    int cnt[101] = {0};
    int ans;

    cin >> a;
    for(int i = 0 ; i < a ; i++){
      cin >> check[i];
    }

    int t = 0;
    while(true){
      if(t == n) break;
      
      for(int i = 0 ; i < a ; i++){
	vector<int>::iterator pos;
	pos = find(v[t].begin(),v[t].end(),check[i]);
	if(pos == v[t].end()){
	  break;
	}
	else{
	  cnt[t]++;
	}
      }
      t++; 
    }

    int cnt1 = 0;
    for(int i = 0 ; i < n ; i++){
      if(cnt[i] == a){
	ans = i+1;
	cnt1++;
      }

    }
    if(cnt1 == 1) cout << ans << endl;
    else cout << "-1" << endl;   
  }

  return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back

typedef long long ll;
typedef pair<int,int> P;

//-----------------------------------------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; 
    while(cin>>n,n)
    {
	bitset<100> bset[101];
	int c,p;
	REP(i,n){
	    cin>>c;
	    REP(j,c){
		cin>>p;
		bset[i].set(p-1);
	    }
	}
	cin>>c;
	REP(i,c){
	    cin>>p;
	    bset[100].set(p-1);
	}

	int cnt=0,idx;
	REP(i,n){
	    if((bset[i]|bset[100])==bset[i]){
		cnt++; idx=i+1;
	    }
	}
	if(cnt==1) cout<<idx<<endl;
	else cout<<-1<<endl;
    }

}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	
	while (1) {
		bool flag = true;
		int n;
		int dp[101][101] = {};
		int m, p;
		int k;
		int l;
		int count = 0;

		cin >> n;
		if (n == 0) {
			break;
		}
		FOR(i, 1, n) {
			cin >> m;
			FOR(t, 1, m) {
				cin >> p;
				dp[i][p] = 1;
			}
		}
		cin >> k;
		vector<int>res(k, 0);
		FOR(i, 0, k-1) {
			cin >> l;
			FOR(t, 1, n) {
				if (dp[t][l] == 1) {
					if (res[i] == 0) {
						res[i] = t;
					}
					else {
						flag = false;
					}
				}
			}
		}
		sort(res.begin(), res.end());
		FOR(i, 0, k - 1) {
			FOR(t, i + 1, k - 1) {
				if (res[i] == res[t]) {
					res[t] = 0;
				}
			}
		}
		FOR(i, 0, k - 1) {
			if (res[i] != 0) {
				count++;
			}
		}
		if (flag) {
			cout << count << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
	

	
}