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>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

VVI _array;
VI info_member;
int n, m;

int main() {
	while ( ~scanf( "%d", &n ) && n ) {
		_array.resize( n );
		for ( int i = 0; i < n; i++ ) {
			scanf( "%d", &m );
			_array[ i ].resize( m );
			for ( int j = 0; j < m; j++ ) {
				scanf( "%d", &_array[ i ][ j ] );
			}
			sort( _array[ i ].begin(), _array[ i ].end() );
		}
		scanf( "%d", &m );
		info_member.resize( m );
		for ( int i = 0; i < m; i++ ) {
			scanf( "%d", &info_member[ i ] );
		}
		sort( info_member.begin(), info_member.end() );
		int ans = 0;
		for ( int i = 0; i < n; i++ ) {
			if ( _array[ i ].size() >= info_member.size() ) {
				bool is_can = true;
				for ( int j = 0; j < info_member.size(); j++ ) {
					if ( !(binary_search( _array[ i ].begin(), _array[ i ].end(), info_member[ j ] )) ) {
						is_can = false;
						break;
					}
				}
				if ( is_can ) {
					if ( ans ) {
						ans = -1;
					}
					else {
						ans = i + 1;
					}
				}
			}
		}
		printf( "%d\n", ans ? ans : -1 );
	}
	return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool
contains(vector<int>&sup, vector<int>&sub) {
  const
    int I = sup.size(),
        J = sub.size();
  int j = 0;
  for (int i = 0; i < I && j < J;) {
    if (sup[i] == sub[j]) ++j;
    else if (sup[i] > sub[j]) return false;
    else ++i;
  }
  return j == J;
}

int main() {

  int n;
  while (cin >> n, n) {
    vector<vector<int>> P(n);
    rep (i, n) {
      int m; cin >> m;
      P[i].resize(m);
      rep (j, m) cin >> P[i][j];
      sort(all(P[i]));
    }
    int k; cin >> k;
    vector<int> ls(k);
    rep (i, k) cin >> ls[i];
    sort(all(ls));

    vector<int> ans;
    rep (i, n) {
      if (contains(P[i], ls)) ans.push_back(i);
    }
    if (ans.size() == 1) {
      cout << -~ans[0] << endl;
    } else {
      cout << -1 << endl;
    }
  }

  return 0;
}

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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        int m[101];
        int p[101][101];
        for(int i = 0; i <n; i++){
            cin >> m[i];
            for (int j = 0; j < m[i]; j++){
                cin >> p[i][j]; 
            }

        }

        int k;
        cin >> k;
        int l[101];
        for(int i = 0; i < k; i++){
            cin >> l[i];
        }

        int ans = 0;
        int count = 0;
        for(int i = 0; i < n; i++){
            int c = 0;
            int memo = 0;
            for(int j = 0; j < k; j++){
                for(int o = 0; o < m[i]; o++){
                    if(l[j] == p[i][o]){
                        c++;
                        memo = i+1;
                    }
                }
            }
            if(c == k){
                ans = memo; 
                count++;
            
            }
        }
        if(count == 1) cout << ans << endl;
        else cout << -1 << endl;

    }


}