import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}
void main(){
	int n;
	while(read(n),n){
		int [][] infos;
		(n+1).times({
			auto info = new int[n+1];
			readArray(info);
			infos ~= info[1..1+info[0]].sort;
		});
		auto leaked = infos[n];
		infos = infos[0..$-1];
		int commiter = -2;
		foreach(int i,info;infos){
			if (leaked.map!(a=>info.canFind(a)).all!"a"){
				if(commiter == -2) commiter = i;	
				else {commiter = -2;break;}
			}
		}
		(commiter+1).writeln;
	}
}