#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl; 
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)            for (auto i : v)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define pb(x)                 push_back(x)
#define bp(x)                 __builtin_popcount(x)
#define mp(x, y)              make_pair((x), (y))
#define fi                    first
#define se                    second
#define setp(x)               setprecision(x)
#define mset(m, v)            memset(m, v, sizeof(m))
#define sz(x)                 (int)(x.size())
static const int INF        = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD        = 1000000007;
static const double PI      = 3.14159265358979;

//#define int                   long long

typedef vector<double>        vd;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef vector<int>           vi;
typedef pair<int, int>        pii;
typedef vector<pii>           vpii;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int _x; scanf("%d", &_x); return _x; }
long long lin() {long long _x; scanf("%lld", &_x); return _x; };

signed main() { 
        int n;
        while (cin >> n) {
                if (!n) break;
                vector<vi> p(n);
                rep(i, n) {
                        int m;
                        cin >> m;
                        vi tmp(m);
                        rep(j, m) {
                                int a;
                                cin >> a;
                                a --;
                                p[i].pb(a);
                        }
                }
                int k = in();
                vi l(k);
                rep(i, k) {
                        cin >> l[i];
                        l[i] --;
                }
                vb f(n, 0);
                vi cnt(n, 0);
                rep(i, k) {
                        rep(j, n) {
                                rep(h, p[j].size()) {
                                        if (p[j][h] == l[i]) {
                                                cnt[j] ++;
                                                f[j] = true;
                                                goto out;
                                        }
                                        else f[j] = false;
                                }                             
                                out:;
                        }
                }
                vi ans;
                rep(i, n) if (f[i] && cnt[i] == k) ans.pb(i);
                if (sz(ans) != 1) cout << -1 << endl;
                else cout << ans[0] + 1 << endl;
        }
        return 0;
}               

Measured memory_bytes: 3208