Problem: Isaac H. Ives attended an international student party and made a lot of girl friends (as many other persons expected). To strike up a good friendship with them, he decided to have dates with them. However, it is hard for him to schedule dates because he made so many friends. Thus he decided to find the best schedule using a computer program. The most important criterion in scheduling is how many different girl friends he will date. Of course, the more friends he will date, the better the schedule is. However, though he has the ability to write a program finding the best schedule, he doesn’t have enough time to write it.

Your task is to write a program to find the best schedule instead of him.



Input

The input consists of a series of data sets. The first line of each data set contains a single positive integer N (N ≤ 1,000) that represents the number of persons Isaac made friends with in the party. The next line gives Isaac’s schedule, followed by N lines that give his new friends’ schedules. Each schedule consists of a positive integer M that represents the number of available days followed by M positive integers each of which represents an available day.

The input is terminated by a line that contains a single zero. This is not part of data sets and should not be processed.

Output

For each data set, print a line that contains the maximum number of girl friends Isaac can have dates with.

Example

Input

3
3 1 3 5
2 1 4
4 1 2 3 6
1 3
0


Output

2

Solution (in CPP):

Solution:
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int V_MAX=1000;

bool augment(int u,bool *vis,int match[2][V_MAX],const vector<int> *G){
	if(u==-1) return true;

	rep(i,G[u].size()){
		int v=G[u][i];
		if(!vis[v]){
			vis[v]=true;
			if(augment(match[1][v],vis,match,G)){
				match[0][u]=v;
				match[1][v]=u;
				return true;
			}
		}
	}
	return false;
}

int bipartite_matching(int L,int R,const vector<int> *G){
	static int match[2][V_MAX];
	rep(u,L) match[0][u]=-1;
	rep(v,R) match[1][v]=-1;

	int res=0;
	static bool vis[V_MAX];
	rep(u,L){
		rep(v,R) vis[v]=false;
		if(augment(u,vis,match,G)) res++;
	}
	return res;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		int m; scanf("%d",&m);
		vector<int> me(m);
		rep(i,m) scanf("%d",&me[i]);
		sort(me.begin(),me.end());
// me can be duplicate!!!!!!!!!!!!!!!!!!!! EVIL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

		// girlfriend -> date
		vector<int> G[V_MAX];
		rep(u,n){
			scanf("%d",&m);
			rep(i,m){
				int girl; scanf("%d",&girl);
// girl can be duplicate!!!!!!!!!!!!!!!!!!!! EVIL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
				if(binary_search(me.begin(),me.end(),girl)){
					int v=lower_bound(me.begin(),me.end(),girl)-me.begin();
					G[u].push_back(v);
				}
			}
		}
		printf("%d\n",bipartite_matching(n,me.size(),G));
	}

	return 0;
}