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;

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);
// lambda: [](T1 x)->T2{return y;}
// simple lambda: [](T x){return x;}

int solve(int N) {
    VVB tb(N, VB(N));
    rep(i, N) {
        tb[i][i] = true;

        int m;
        cin >> m;
        rep(j, m) {
            int p;
            cin >> p;
            tb[i][p - 1] = true;
        }
    }

    int K;
    cin >> K;
    VI ls(K);
    rep(i, K) {
        cin >> ls[i];
        --ls[i];
    }

    int ans = -1;
    
    rep(i, N) {
        bool all_known = true;

        for (auto j : ls) {
            all_known &= tb[i][j];
        }

        if (all_known) {
            if (ans == -1) ans = i + 1;
            else return -1;
        }
    }
    
    return ans;
}

int main(void) {
    int N;
    while (cin >> N, N) cout << solve(N) << endl;

    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

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

	int N; while (cin >> N && N != 0)
	{
		vector<vector<int>> dat(N + 2, vector<int>(0));
		rep(i, N)
		{
			int M = 0; cin >> M;
			rep(j, M)
			{
				int tmp; cin >> tmp;
				dat[i].push_back(tmp);
			}
		}
		int K; cin >> K;
		vector<int> tar(K, 0);
		rep(i, K) { cin >> tar[i]; }
		vector<int> ans(N, 0);
		int cri = 0;
		rep(i, N) rep(j, (int)tar.size())
		{
			int tmp = count(all(dat[i]), tar[j]);
			if (tmp >= 1) { ans[i]++; }
			if (ans[i] == (int)tar.size()) { cri++; }
		}
		if (cri == 1){printf("%d\n", max_element(all(ans)) - ans.begin() + 1); }
		else { printf("-1\n"); }
	}

	return 0;
}

C++: #include<iostream>
#include<set>
using namespace std;
int main(){
  int n;
  while(1){
    cin >> n;
    if(n==0)break;
    set<int> st;
    int a[100][100];
    int b[101];
    for(int i=0;i<n;i++){
      cin >> b[i];
      for(int j=0;j<b[i];j++){
	cin >> a[i][j];
      }
    }
    cin >> b[100];
    int S;
    for(int i=0;i<b[100];i++){
      cin >> S;
      st.insert(S);
    }
    int s=0;
    for(int i=0;i<n;i++){
      int c=0;
      for(int j=0;j<b[i];j++){
	c+=st.count(a[i][j]);
      }
      if(c==b[100]){
	if(s==0)s=i+1;
	else{
	  s=-1;
	  i=n;
	}
      }
    }
    if(s<=0)cout << -1 << endl;
    else cout << s << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <memory.h>
int main(void){
	int n,m,t,p[100][101],k,l[100],i,j,ans,f;
	while(1){
		scanf("%d",&n);
		if(!n)
			break;
		memset(p,0,sizeof(p));
		f=1;
		ans=-1;
		for(i=0;i<n;i++){
			scanf("%d",&m);
			for(j=0;j<m;j++){
				scanf("%d",&t);
				p[i][t]++;
			}
		}
		scanf("%d",&k);
		for(i=0;i<k;i++)
			scanf("%d",&l[i]);
		for(i=0;i<n;i++){
			for(j=0;j<k;j++){
				if(!p[i][l[j]])
					break;
			}
			if(j==k&&f){
				ans=i+1;
				f=0;
			}
			else if(j==k&&!f)
				ans=-1;
		}
		printf("%d\n",ans);
	}
	return 0;
}