import core.stdc.stdio;
import std.typecons;
import std.algorithm;

void main(){
	int n,e,t;
	scanf("%d%d%d",&n,&e,&t);
	--t;
	long[] cost = new long[n];
	static immutable int inf = 1145141919;
	bool[] used = new bool[n];
	foreach(i;0..n){
		int w;
		scanf("%d",&w);
		if(w==1){
			cost[i]=1;
			used[i]=true;
		}else
			cost[i]=inf;
	}
	alias Tuple!(long,"cost",int,"g",int[],"f") cgf;
	cgf[] rec = new cgf[e];
	int[][] h = new int[][n];
	void CalcCost(ref cgf r){
		sort!((a,b)=>cost[a]<cost[b])(r.f);
		r.cost=0;
		foreach(i,v;r.f)
			r.cost=max(r.cost,r.f.length-i-1+cost[v]);
	}
	foreach(i;0..e){
		int c;
		scanf("%d%d",&rec[i].g,&c);
		rec[i].g--;
		rec[i].f=new int[c];
		foreach(ref v;rec[i].f){
			scanf("%d",&v);
			h[--v]~=i;
		}
		CalcCost(rec[i]);
	}
	while(cost[t]==inf){
		cgf mn = cgf(cast(long)inf,-1,[]);
		foreach(r;rec)
			if(!used[r.g]&&r.cost<mn.cost)
				mn=r;
		if(mn.g==-1){
			printf("-1\n");
			return;
		}
		used[mn.g]=true;
		cost[mn.g]=mn.cost;
		foreach(j;h[mn.g])
			CalcCost(rec[j]);
	}
	printf("%lld\n",cost[t]);
}