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 <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i, 0, n)

int main() {
	int N;
	while(cin >> N, N) {
		vvi data(N, vi(N));

		int M, tmp;
		REP(i, N) {
			cin >> M;
			REP(j, M) {
				cin >> tmp;
				data[i][tmp-1] = 1;
			}
		}

		int K;
		cin >> K;
		vi rdata(K);
		REP(i, K) {
			cin >> tmp;
			rdata[i] = tmp-1;
		}

		int ans = -1;
		REP(i, N) {
			bool flag = true;
			REP(j, K) {
				if(data[i][rdata[j]] != 1) {
					flag = false;
					break;
				}
			}
			if(flag) {
				if(ans != -1) {
					ans = -1;
					goto show;
				} else {
					ans = i+1;
				}
			}
		}

show:
		cout << ans << endl;
	}
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a[n+2][n+2]={0},m;
    r(i,n+1){
      cin>>m;
      r(j,m)cin>>a[i][j];
      sort(a[i],a[i]+m);
    }
    int c=0,p,x=0,u,ans=0;
    r(i,n){p=0;
      for(int j=0;a[i][j]!=0;j++){
        if(a[i][j]==a[n][p])p++;
      }
      if(p==m){
        x++;
        ans=i;
      }
    }
    if(x==1)cout<<ans+1<<endl;
    else cout<<-1<<endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
string IntToString(int);
int StringToInt(string);
int main(){
  while(1){
    int n;
    cin >> n;
    if(n == 0)break;
    vector<int> M(n);
    vector<bitset<101> > P(n,bitset<101>(0));
    for(int i = 0;i < n;i++){
      cin >> M[i];
      for(int j = 0;j < M[i];j++){
	int tmp;
	cin >> tmp;
	bitset<101> tmp_bit(1 << (tmp-1));
	P[i] = (P[i] | tmp_bit);
      }
    }
    int more_n;
    cin >> more_n;
    bitset<101> more(0);
    for(int i = 0;i < more_n;i++){
      int tmp;
      cin >> tmp;
      bitset<101> tmp_bit(1 << (tmp-1));
      more = (more | tmp_bit);
    }
    int flag = 0;
    int ans;
    for(int i = 0;i < n;i++){
      if((P[i] & more) == more){
	ans = i+1;
	flag++;
      }
    }
    if(flag == 1)cout << ans << endl;
    else cout << "-1" << endl;
    
  }
  return 0;   
}
string IntToString(int number){
  stringstream ss;
  ss << number;
  return ss.str();
}
int StringToInt(string number){
  stringstream ss;
  ss << number;
  int numInt;
  ss >> numInt;
  return numInt;
  
}

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

int main() {

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    vector< long long int > v0, v1;

    for ( long long int i = 0; i < n+1; i++ ) {

      long long int m;
      cin >> m;

      long long int p0 = 0;
      long long int p1 = 0;

      for ( long long int j = 0; j < m; j++ ) {

	long long int in;
	cin >> in;
	if ( in < 50 ) {
	  p0 += ( 1LL << in );
	}else {
	  p1 += ( 1LL << ( in - 50 ) );
	}

      }

      v0.push_back( p0 );
      v1.push_back( p1 );

    }

    long long int ans = -1;

    for ( long long int j = 0; j < n; j++ ) {

      if ( ( v0[j] & v0[n] ) == v0[n] && ( v1[j] & v1[n] ) == v1[n] ) {

	if ( ans == -1 ) {
	  ans = j + 1;
	}else {
	  ans = -1;
	  break;
	}

      }

    }

    cout << ans << endl;

  }

  return 0;

}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	bool A[100][100];
	bool B[100];
	for (int N; cin >> N&&N;) {
		memset(A, 0, sizeof(A));
		memset(B, 1, sizeof(B));
		for (int i = 0; i < N; i++) {
			int M; cin >> M;
			for (int j = 0; j < M; j++) {
				int p; cin >> p;
				A[i][p] = true;
			}
		}
		int K; cin >> K;
		int cnt = N;
		for (int i = 0; i < K; i++) {
			int l; cin >> l;
			for (int j = 0; j < N; j++) {
				if (B[j] && !A[j][l]) {
					B[j] = false;
					cnt--;
				}
			}
		}
		
		//cout << " " << cnt << endl;
		if (cnt == 1) {
			for (int i = 0; i < N; i++) {
				if (B[i]) {
					cout << i + 1 << endl;
				}
			}
		}
		else {
			cout << -1 << endl;
		}
	}
	return 0;
}