The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.

Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).

Input

The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages.

Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki integers — aij (1 ≤ aij ≤ m) — the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.

The numbers in the lines are separated by single spaces.

Output

Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).

Examples

Input

5 5
1 2
2 2 3
2 3 4
2 4 5
1 5


Output

0


Input

8 7
0
3 1 2 3
1 1
2 5 4
2 6 7
1 3
2 7 4
1 1


Output

2


Input

2 2
1 2
0


Output

1

Note

In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.

In the third sample employee 2 must learn language 2.
							import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

											public class Solution1 implements Runnable
											{
												static final long MAX = 1000003L;
												static class InputReader
												{
													private InputStream stream;
													private byte[] buf = new byte[1024];
													private int curChar;
													private int numChars;
													private SpaceCharFilter filter;
													private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
											 
													public InputReader(InputStream stream)
													{
														this.stream = stream;
													}
													
													public int read()
													{
														if (numChars==-1) 
															throw new InputMismatchException();
														
														if (curChar >= numChars)
														{
															curChar = 0;
															try 
															{
																numChars = stream.read(buf);
															}
															catch (IOException e)
															{
																throw new InputMismatchException();
															}
															
															if(numChars <= 0)				
																return -1;
														}
														return buf[curChar++];
													}
												 
													public String nextLine()
													{
														String str = "";
											            try
											            {
											                str = br.readLine();
											            }
											            catch (IOException e)
											            {
											                e.printStackTrace();
											            }
											            return str;
													}
													public int nextInt()
													{
														int c = read();
														
														while(isSpaceChar(c)) 
															c = read();
														
														int sgn = 1;
														
														if (c == '-') 
														{
															sgn = -1;
															c = read();
														}
														
														int res = 0;
														do 
														{
															if(c<'0'||c>'9') 
																throw new InputMismatchException();
															res *= 10;
															res += c - '0';
															c = read();
														}
														while (!isSpaceChar(c)); 
														
														return res * sgn;
													}
													
													public long nextLong() 
													{
														int c = read();
														while (isSpaceChar(c))
															c = read();
														int sgn = 1;
														if (c == '-') 
														{
															sgn = -1;
															c = read();
														}
														long res = 0;
														
														do 
														{
															if (c < '0' || c > '9')
																throw new InputMismatchException();
															res *= 10;
															res += c - '0';
															c = read();
														}
														while (!isSpaceChar(c));
															return res * sgn;
													}
													
													public double nextDouble() 
													{
														int c = read();
														while (isSpaceChar(c))
															c = read();
														int sgn = 1;
														if (c == '-') 
														{
															sgn = -1;
															c = read();
														}
														double res = 0;
														while (!isSpaceChar(c) && c != '.') 
														{
															if (c == 'e' || c == 'E')
																return res * Math.pow(10, nextInt());
															if (c < '0' || c > '9')
																throw new InputMismatchException();
															res *= 10;
															res += c - '0';
															c = read();
														}
														if (c == '.') 
														{
															c = read();
															double m = 1;
															while (!isSpaceChar(c)) 
															{
																if (c == 'e' || c == 'E')
																	return res * Math.pow(10, nextInt());
																if (c < '0' || c > '9')
																	throw new InputMismatchException();
																m /= 10;
																res += (c - '0') * m;
																c = read();
															}
														}
														return res * sgn;
													}
													
													public String readString() 
													{
														int c = read();
														while (isSpaceChar(c))
															c = read();
														StringBuilder res = new StringBuilder();
														do 
														{
															res.appendCodePoint(c);
															c = read();
														} 
														while (!isSpaceChar(c));
														
														return res.toString();
													}
												 
													public boolean isSpaceChar(int c) 
													{
														if (filter != null)
															return filter.isSpaceChar(c);
														return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
													}
												 
													public String next() 
													{
														return readString();
													}
													
													public interface SpaceCharFilter 
													{
														public boolean isSpaceChar(int ch);
													}
												}
											 	
												public static void main(String args[]) throws Exception
												{
													new Thread(null, new Solution1(),"Solution",1<<26).start();
												}	
												public static int gcd(int a, int b)
											    {
											        if (a == 0)
											            return b;
											         
											        return gcd(b%a, a);
											    }
												int lcm(int a, int b)
												{
												    return (a*b)/gcd(a, b);
												}
												ArrayList<Integer> adj[];
												public void run() 
												{
													InputReader sc= new InputReader(System.in);
													PrintWriter w= new PrintWriter(System.out);
													int n = sc.nextInt();
													int m = sc.nextInt();
													int[][] arr = new int[n][];
													boolean flag=  false;
													for(int i = 0;i < n;i++) {
														int k = sc.nextInt();
														if(k > 0) {
															flag=  true;
														}
														arr[i] = new int[k];
														for(int j = 0;j < k;j++) {
															arr[i][j] = sc.nextInt();
														}
														Arrays.sort(arr[i]);
													}
													adj = new ArrayList[n];
													visited=  new boolean[n];
													for(int i = 0;i < n;i++) {
														adj[i] = new ArrayList();
													}
													for(int i = 0;i < n;i++) {
														for(int j = i+1;j < n;j++) {
															for(int k = 0;k < arr[i].length;k++) {
																int y = Arrays.binarySearch(arr[j],arr[i][k]);
																if(y >= 0) {
																	adj[i].add(j);
																	adj[j].add(i);
																}
															}
														}
													}
													int count = 0;
													for(int i = 0;i < n;i++) {
														if(!visited[i]) {
															bfs(i);
															count++;
														}
													}
													if(!flag) {
														w.println(count);
													}else
														w.println(count-1);
													w.close(); 
												}
												boolean[] visited;
												void bfs(int a) {
													Queue<Integer> q = new LinkedList();
													q.add(a);
													visited[a] = true;
													while(!q.isEmpty()) {
														int x = q.poll();
														Iterator<Integer> it = adj[x].iterator();
														while(it.hasNext()) {
															int temp = it.next();
															if(!visited[temp]) {
																visited[temp] = true;
																q.add(temp);
															}
														}
													}
												}
												int count = 0;
												int an = 0;
												void recur(int ind,int size,int coun,String b) {
													if(ind == size) {
														if(coun == an) {
															count++;
														}
														return;
													}
													if(b.charAt(ind) == '?') {
														recur(ind+1,size,coun+1,b);
														recur(ind+1,size,coun-1,b);
													}else {
														if(b.charAt(ind) == '+') {
															recur(ind+1,size,coun+1,b);
														}else {
															recur(ind+1,size,coun-1,b);
														}
													}
												}
												ArrayList<Integer> segTree[];
												int[] ans;
												void build(int l,int r,int pos){
													if(l == r){
														segTree[pos] = new ArrayList();
														segTree[pos].add(ans[l]);
														return;
													}
													int mid = (l+r)/2;
													build(l, mid, 2*pos+1);
													build(mid+1, r, 2*pos+2);
													segTree[pos] = merge(segTree[2*pos+1],segTree[2*pos+2]);
												}
												ArrayList<Integer> merge(ArrayList<Integer> a,ArrayList<Integer> b){
													ArrayList<Integer> c = new ArrayList();
													int i = 0;
													int j = 0;
													while(i < a.size() && j < b.size()){
														if(a.get(i) <= b.get(j)){
															c.add(a.get(i));
															i++;
														}else{
															c.add(b.get(j));
															j++;
														}
													}
													while(i < a.size()){
														c.add(a.get(i));
														i++;
													}
													while(j < b.size()){
														c.add(b.get(j));
														j++;
													}
													return c;
												}
												int query(int l,int r,int start,int end,int pos,int val){
													if(l > end || r < start || l > r){
														return 0;
													}
													if(l >= start && r <= end){
														int ans = -1;
														l = 0;
														r = segTree[pos].size()-1;
														while(l <= r){
															int mid = (l + r)/2;
															if(segTree[pos].get(mid) <= val){
																ans = mid;
																l = mid+1;
															}else{
																r = mid-1;
															}
														}
													    return ans + 1;
													}
													int mid = (l + r)/2;
													int p1 = query(l,mid, start, end, 2*pos+1, val);
													int p2 = query(mid+1, r, start, end, 2*pos+2, val);
													return (p1+p2);
												}
												long[][] multiply(long[][] a,long[][] b){
													long[][] temp = new long[3][3];
													for(int i = 0;i < 3;i++) {
														for(int j = 0;j < 3;j++) {
															for(int k = 0;k < 3;k++) {
																temp[i][j] = (temp[i][j] + (a[i][k] * b[k][j]) % MAX)%MAX;
															}
														}
													}
													return temp;
												}
												long pow(long[][] f,int val,long a,long b) {
													long[][] in = {{1,0,0},{0,1,0},{0,0,1}};
													while(val > 0) {
														if((val & 1) == 1) {
															in = multiply(in,f);
														}
														val = val/2;
														f = multiply(f, f);
													}
													return ((4*in[0][0])%MAX + (2*in[0][1])%MAX + in[0][2])%MAX;
												}
												   static long power(long x, long y,long p)
												    {
												        // Initialize result
												        long res = 1;     
												        
												        // Update x if it is more  
												        // than or equal to p
												        x = x % p; 
												     
												        while (y > 0)
												        {
												            // If y is odd, multiply x
												            // with result
												            if((y & 1)==1)
												                res = (res * x) % p;
												     
												            // y must be even now
												            // y = y / 2
												            y = y >> 1; 
												            x = (x * x) % p; 
												        }
												        return res;
												    }
												static class Pair implements Comparable<Pair>{
													int a;
													int b;
													int c;
													Pair(int a,int b,int c){
														this.a  =a;
														this.b = b;
														this.c = c;
													}
													Pair(){}	
													public boolean equals(Object o)
													{
														Pair p = (Pair)o;
														
														return true;
													}
													
													public int compareTo(Pair p){
														
														return Integer.compare(this.c,p.c);
													}
												
												}
												
								}