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

int main()
{
	while (true) {
		int N;
		cin >> N;

		if (N == 0) {
			break;
		}

		vector<vector<int>> M(N);
		vector<int> size(N);
		
		for (int i = 0; i < N; i++) {
			cin >> size[i];

			for (int j = 0; j < size[i]; j++) {
				int temp;
				cin >> temp;
				M[i].push_back(temp);
			}
		}

		int k;
		cin >> k;

		vector<int> K;

		for (int i = 0; i < k; i++) {
			int temp;
			cin >> temp;
			K.push_back(temp);
		}

		int ans = -1;

		for (int i = 0; i < N; i++) {
			bool ok = true;

			for (int j = 0; j < k; j++) {
				bool flag = false;
				for (int x = 0; x < size[i]; x++) {
					if (K[j] == M[i][x]) {
						flag = true;
						break;
					}
				}

				if (flag == false) {
					ok = false;
					break;
				}
			}

			if (ok == true) {
				if (ans != -1) {
					ans = -1;
					break;
				}
				else {
					ans = i + 1;
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

C++: #include "bits/stdc++.h"
#include <random>
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;
 
 
void reader(int &a){scanf("%d",&a);}
void reader(double &a){scanf("%lf",&a);}
void reader(char a[]){scanf("%s",a);}
void reader(ll &a){scanf("%lld",&a);}
void reader(ull &a){scanf("%llu",&a);}
// void reader(string& a){cin >> a;};
template<class T,class U> void reader(T& t,U& u){reader(t); reader(u);}
template<class T,class U,class V> void reader(T& t,U& u,V& v){reader(t); reader(u); reader(v);}
 
void writer(int a,char c) {printf("%d",a); putchar(c);}
void writer(ll a,char c) {printf("%lld",a); putchar(c);}
void writer(double a,char c) {printf("%.20lf",a); putchar(c);}
void writer(char a[]) {printf("%s",a);};
void writer(char a[],char c) {printf("%s",a);putchar(c);};
void writer(char a,char c) {putchar(a); putchar(c);};
template<class T>void writerLn(T t){writer(t,'\n');}
template<class T,class U>void writerLn(T t,U u){writer(t,' ');writer(u,'\n');}
template<class T,class U,class V> void writerLn(T t,U u,V v){writer(t,' ');writer(u,' ');writer(v,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
template<class T> void writerVec(vector<T> x){int n=x.size();int i;if(!n){putchar('\n');return;}rep(i,n-1) writer(x[i],' ');writer(x[n-1],'\n');}
 
vector<std::string> split(const std::string &str, char sep){std::vector<std::string> v;std::stringstream ss(str);std::string buffer;while(std::getline(ss,buffer,sep)){v.push_back(buffer);}return v;}
 
// #define int ll
bool test = 1;
int dx[] = { 0,0,1,-1 };
int dy[] = { 1,-1,0,0 };

//..................
ull mod = (int)1e9 + 7;
signed main(){
  int i,j,k,l;
  string s;
  while(1) {
	int N,K;
	vector<int> connect[100];
	int l[100];
	cin >> N;
	if(N == 0) return 0;
	rep(i,N) {
	  int M;
	  cin >> M;
	  rep(j,M) {
		int p;
		cin >> p;
		connect[i].push_back(p);
	  }
	}
	cin >> K;
	rep(i,K) cin >> l[i];
	int ans = -1;
	rep(i,N) {
	  bool correct = true;
	  rep(j,K) {
		if(!binary_search(ALL(connect[i]),l[j])) {
		  correct = false;
		}
	  }
	  if(ans == -1 && correct) ans = i;
	  else if(ans != -1 && correct) {
		ans = -1;
		break;
	  }
	}
	if(ans == -1) cout << -1 << endl;
	else cout << ans+1 << endl;
  }
  return 0;
}

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

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

const unsigned long mod = 1000000007;
const double EPS = 0.00000001;
const int INF = (1 << 29);

typedef std::pair<int, int> pii;

template<typename T>
void print_array(T *A_, s32 size) {
  //printf("%d\n", size);
  if( size != 0 ) {
    for(int i = 0; i < size - 1; ++i) {
      printf("%d ", A_[i]);
    }
    printf("%d\n", A_[size - 1]);
  }
}

int solve(int m, int i, int j, int k, int l) {
  int total = i * 10 + j * 50 + k * 100 + l * 500; 
  if( total < m ) return -1;
  int diff = total - m;
  int res = 0;
  res += (diff / 10 % 10) % 5 + (diff / 10 % 10) / 5;
  res += (diff / 100 % 10) % 5 + (diff / 100) / 5;
  return res;
}
  

auto main() -> int {

  for(;;) {
    int n;
    std::cin >> n;
    if( n == 0 ) break;

    bool know[128][128];
    for(int i = 0; i < 128; ++i) for(int j = 0; j < 128; ++j) know[i][j] = false;

    for(int i = 1; i <= n; ++i) {
      int m;
      std::cin >> m;
      for(int j = 0; j < m; ++j) {
        int p;
        std::cin >> p;
        know[i][p] = true;
      }
    }

    bool check[128];
    for(int i = 0; i < 128; ++i) check[i] = false;
    int k;
    std::cin >> k;
    for(int i = 0; i < k; ++i) {
      int l;
      std::cin >> l;
      check[l] = true;
    }
    
    

    int res = 0;
    for(int i = 1; i <= n; ++i) {
      for(int j = 1; j <= n; ++j) {
        if( not know[i][j] and check[j] ) {
          goto label_1;
        }
      }
      if( res == 0 ) {
        res = i;
      }
      else {
        res = -1;
        goto label_2;
      }
        
    label_1:;
    }
  label_2:;
    if( res == 0 ) res = -1;
    std::cout << res << std::endl;    
  }
  
  return 0;
}