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>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	// n := 人数
	int n;
	while( cin >> n , n ){
		// s[i][j] := i が j さんの個人情報を知っているかどうか.
		int s[101][101] = {0};
		
		for(int i=0 ; i < n ; i++ ){
			int m;
			cin >> m;
			for(int j=0 ; j < m ; j++ ){
				int p;
				cin >> p;
				p--;
				// i さんは p さんの個人情報を知っている.
				s[i][p] = 1;
			}
		}
		// k := 個人情報が漏洩した人数.
		int k;
		cin >> k;
		// L := 個人情報が漏洩した人の番号を保持する配列.
		vector<int> L(k);
		for(int i=0 ; i < k ; i++ ){
			cin >> L[i];
			L[i]--;
		}
		
		// ans := 個人情報を漏らした可能性のある人の番号を保持する配列.
		vector<int> ans;
		
		for(int y=0 ; y < n ; y++ ){
			bool flag = true;
			// foo := y さんが知っている人の番号を保持する配列
			vector<int> foo;
			for(int x=0 ; x < n ; x++ ){
				if( s[y][x] ) foo.push_back( x );
			}
			for(int i=0 ; i < L.size() ; i++ ){
				// x さんは L[i] さんの情報を漏らした可能性がなければ flag を false にしておく.
				if( count(foo.begin(), foo.end(), L[i] ) == 0 ){
					flag = false;
				}
			}
			// x さん が個人情報を漏らした可能性のある人なら ans に追加.
			if( flag ) ans.push_back( y );
		}
		
		// 個人情報を漏らした可能性のある人物が一人だけならその番号を出力, そうでなければ -1 を出力.
		if( ans.size() == 1 ){
			cout << (ans[0]+1) << endl;
		}else{
			cout << -1 << endl;
		}
	}
}

C++: #include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        vector<set<int>> v(n);
        rep(i,n){
            int a;cin>>a;
            rep(j,a){
                int b;cin>>b;
                v[i].insert(b);
            }
        }
        int ansc=0,ans=0;
        int ksize;cin>>ksize;
        vector<int> k(ksize);
        rep(i,ksize)cin>>k[i];
        rep(i,n) {
            bool f = true;
            rep(j, ksize) {
                if (v[i].find(k[j]) == v[i].end()) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ans = i + 1;
                ansc++;
            }
        }
        if(ansc==1){
        cout<<ans<<endl;
        }else{
            cout<<-1<<endl;
        }
        
        
        
    }

    return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vvi v(n);
    rep(i, n) {
      int m;
      cin >> m;
      while (m--) {
        int p;
        cin >> p;
        v[i].pb(p);
      }
    }
    int k;
    cin >> k;
    vi w(k);
    rep(i, k) cin >> w[i];
    int c = 0, p;
    rep(i, v.size()) {
      vi r;
      set_difference(all(w), all(v[i]), back_inserter(r));
      if (r.size() == 0) {
        c++;
        p = i;
      }
    }
    cout << (c == 1 ? p + 1 : -1) << endl;
  }
}

C++: #include <iostream>

using namespace std;

int main()
{
  int n;
  int i,j,k;
  while(1){
	cin >> n;
	if(n == 0) break;
	int m[100];
	int p[100][100];

	for (i = 0; i < n; i++) {
	  cin >> m[i];
	  for (j = 0; j < m[i]; j++) {
		cin >> p[i][j];
	  }
	}
	cin >> k;
	int hoge;
	int l[100];
	for(hoge = 0;hoge < k; hoge ++){
	  cin >> l[hoge];
	}

	int ans = 0;
	int c = 0;

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

	if(ans == 0) ans = -1;


	cout << ans << endl;

  }
  return 0;
}