#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
ll dp[310];
vvint vv[310];
int n;
int used[310];
ll foo(int x){
	if(dp[x]!=INF){
		return dp[x];
	}
	if(used[x]) return -1;
	// dump(x+1);
	ll ret=INF+1;
	used[x]=1;
	bool f=false;
	rep(i,vv[x].size()){
		vll tmp;
		rep(j,vv[x][i].size()){
			ll t=foo(vv[x][i][j]);
			if(t==-1) f=true;
			tmp.PB(foo(vv[x][i][j]));
		}
		sort(ALL(tmp));
		reverse(ALL(tmp));
		ll t1=0;
		ll t2=0;
		rep(i,tmp.size()){
			if(t2>=tmp[i]){
				// t2-=tmp[i];
				t2--;
			}
			else{
				t1+=tmp[i]-t2;
				t2=tmp[i]-1;
			}
		}
		ret=min(ret,t1);
	}
	used[x]=0;
	if(f) return INF;
	dp[x]=ret;
	rep(i,vv[x].size()){
		rep(j,vv[x][i].size()){
			foo(vv[x][i][j]);
		}
	}
	return dp[x];
}
void mainmain(){
	int e,T;
	cin>>n>>e>>T;
	// dump(n);
	T--;
	vint w(n);
	rep(i,n) cin>>w[i];
	rep(i,e){
		int a,b;
		// dump(a);
		cin>>a>>b;
		a--;
		int tt=vv[a].size();
		vv[a].resize(vv[a].size()+1);
		rep(j,b){
			int t;
			cin>>t;
			t--;
			vv[a][tt].PB(t);
		}
	}
	rep(i,310){
		dp[i]=INF;
	}
	rep(i,n){
		if(w[i]) dp[i]=1;
	}
	bool update=true;
	while(update){
		update=false;
		rep(i,n){
			rep(j,vv[i].size()){
				ll t1=0;
				ll t2=0;
				vll tmp(vv[i][j].size());
				rep(k,vv[i][j].size()){
					tmp[k]=dp[vv[i][j][k]];
				}
				sort(ALL(tmp));
				reverse(ALL(tmp));
				rep(k,tmp.size()){
					if(t2>=tmp[k]){
						t2--;
					}
					else{
						t1+=tmp[k]-t2;
						t2=tmp[k]-1;
					}
				}
				if(t1<dp[i]){
					update=true;
					dp[i]=t1;
				}
			}
		}
	}
	// foo(T);
	rep(i,n){
		// cout<<i+1<<" "<<dp[i]<<" "<<used[i]<<endl;
	}
	if(dp[T]>=INF) cout<<-1<<endl;
	else cout<<dp[T]<<endl;
}


main() {
    mainmain();
}

Measured memory_bytes: 1312