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 <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
 
typedef long long ll;
int const inf = 1<<29;
 
namespace flow {
 
class bipartite_matching {
private:
 
  int V;
  vector<vector<int>> G;
  vector<int> match;
  vector<bool> used;
 
  bool dfs(int v) {
    used[v] = 1;
    for(auto& u: G[v]) {
      int w = match[u];
      if(w < 0 || (!used[w] && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }
 
 
public:
 
  bipartite_matching(int V): V(V) {
    G.resize(V), match.resize(V), used.resize(V);
  }
 
  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }
 
  int maximum_matching() {
    int ret = 0;
    match.clear(), match.resize(V, -1);
    rep(v, V) {
      if(match[v] < 0) {
        used.clear(), used.resize(V, 0);
        if(dfs(v)) { ret ++; }
      }
    }
    return ret;
  }
};
 
}
 
int main() {
 
  for(int N; cin >> N && N;) {
    int M; cin >> M;
 
    int dcnt = 0;
    unordered_map<int, int> dayidx;
    rep(i, M) {
      int x; cin >> x;
      if(dayidx.find(x) == dayidx.end()) {
        dayidx[x] = dcnt++;
      }
    }
 
    flow::bipartite_matching bp(dcnt + N);
 
    rep(girl, N) {
      cin >> M;
      rep(i, M) {
        int k; cin >> k;
        if(dayidx.find(k) != dayidx.end())
          bp.add_edge(dayidx[k], dcnt + girl);
      }
    }
 
    cout << bp.maximum_matching() << endl;
  }
   
  return 0;
}