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>

using namespace std;

int main()
{
  int n;
  cin >>n;

  while(n){	

	int m[200][100];
	int hoge[100];
	//initialize
	
	for (int i = 0; i < n; i++) {
	  cin >> hoge[i];
	  for (int j = 0; j < hoge[i]; j++) {
		cin >> m[i][j];
	  }
	}
	int fuga=0;
	cin >> fuga;
	int k[200];
	for (int l = 0; l < fuga; l++) {
	  cin >> k[l];
	}
	//end of input

	if(fuga ==0) cout << -1 << endl;

	else{	
	  int a,b,c;
	  int ans[200];
	  int aa=0;
	  ans[0]=0;
	
	  for(a=0;a<n;a++){
		b=0;
		//		cout << "a="<<a <<endl; 
		for(c=0;c<hoge[a];c++){
		  //		  cout << "c="<<c << endl;
		  if(k[b]==m[a][c]){
			b++;
		  }
		}
		
		if(b>=fuga){
		  ans[aa] = a;
		  aa++;
		  //		  cout << a << endl;//
		
		}
	  }
	  if(aa==1) cout << ans[0]+1 << endl;
	  else cout << -1 << endl;
	}
	
	cin >> n;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m, p, k, l;
vector<V> vvi;
bool f[100];

int main(){
	while (cin >> n&&n){ 
		vvi.clear();
		fill(f, f + 100, 1);
		REP(i, n){
			cin >> m;
			V vi;
			REP(j, m){
				cin >> p;
				vi.push_back(p);
			}
			vvi.push_back(vi);
		}
		cin >> k;
		REP(i, k){
			cin >> l;
			REP(j, vvi.size()){
				if (find(ALL(vvi[j]), l) == vvi[j].end()){
					f[j] = 0;
				}
			}
		}
		int co = 0;
		REP(i, n){
			if (f[i])co++;
		}
		if (co == 1){
			REP(i, n){
				if (f[i])cout << i + 1 << endl;
			}
		}
		else{
			cout << -1 << endl;
		}
	}
}

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

using namespace std;

int main() {
	int N;
	while(cin >> N, N) {
		vector< set<int> > M(N, set<int>());
		for(int i = 0; i < N; i++) {
			int m; cin >> m;
			for(int j = 0; j < m; j++) {
				int tmp; cin >> tmp;
				M[i].insert(tmp);
			}
		}
		int K ; cin >> K;
		vector<int> l(K);
		for(int i = 0; i < K; i++) cin >> l[i];

		int ans = -1;
		for(int i = 0; i < N; i++) {
			bool flag = true;
			for(int j = 0; j < K; j++) {
				if(M[i].find(l[j]) == M[i].end()) {
					flag = false;
				}
			}
			if(flag && ans != -1) {ans = -1; break;}
			if(flag) ans = i+1;
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define SZ(x) (int)(x).size()
#define pb push_back

typedef vector<int> vint;

bool search(vint v, int x) {
    for(auto& i : v) if(i == x) return true;
    return false;
}

bool OK(vint p, vint l) {
    if(SZ(p) < SZ(l)) return false;
    for(auto& li : l) {
        if(search(p, li)) continue;
        return false;
    }
    return true;
}

void solve(int n) {
    vector<vector<int>> ps;
    rep(i,n) {
        int m; cin>>m;
        vector<int> p(m);
        rep(i,m) cin>>p[i];
        ps.pb(p);
    }
    int k; cin>>k;
    vector<int> l(k);
    rep(i,k) cin>>l[i];

    int cnt=0, ans=0;
    rep(i,n) {
        if(OK(ps[i], l)) {
            cnt++;
            ans = i+1;
        }
    }
    cout << (cnt==1 ? ans : -1) << "\n";
}

int main() {
    for(int n; cin>>n && n; ) solve(n);
    return 0;
}

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

int main()
{
	int n;
	while(cin>>n,n)
	{
		int p[n+1][100];
		for(int i=1;i<=n;i++)
		{
			cin>>p[i][0];
			for(int j=1;j<=p[i][0];j++) cin>>p[i][j];
		}
		int num;
		int k[100];
		cin>>num;
		for(int i=0;i<num;i++) cin>>k[i];

		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if(p[i][0]<num) continue;
			int cnt=0;
			for(int j=0;j<num;j++)
			{
				for(int l=1;l<=p[i][0];l++)
				{
					if(k[j]==p[i][l]) {cnt++; break;}
				}
			}
			if(cnt==num)
			{
				if(!ans) ans=i;
				else ans=-1;
			}
		}
		if(ans==0) ans=-1;
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;
using namespace std;

signed main(){
  int n;
  while(cin >> n, n != 0){
    vector<vector<int>> p(n);
    for(int range(i,0,n)){
      int m;
      cin >> m;
      p[i] = vector<int>(m);
      for(int range(j,0,m)){
        cin >> p[i][j];
      }
      sort(all(p[i]));
    }
    int k;
    cin >> k;
    vector<int> l(k);
    for(int range(j, 0, k)){
      cin >> l[j];
    }
    sort(all(l));
    int id = -2;

    for(int range(i,0,n)){

      if(includes(all(p[i]), all(l))){
        if(id==-2){
          id = i;
        }else{
          id = -3;
        }
      }
    }
    cout << max(-1ll, id+1) << endl;
  }
}