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.*;
import java.math.BigInteger;
import java.util.*;



 public class Main {
	public static InputReader in;
    public static PrintWriter pw;
	public static void main(String args[]) {
		new Thread(null, new Runnable() {
            public void run() {
                try{
                    solve();
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
        }, "1", 1 << 26).start();
    }
	static TreeSet<Integer> set;
	static ArrayList<Integer> g[];
	static boolean visited[];
	static long edje=0;
    static boolean vis[];
	static int parent[];
	static int col[];
	static boolean[] vis1;
	static int Ans=0;
	static int min=Integer.MAX_VALUE;
	static int val[];
	static int degree[];
	static int a[];
	static int f[];
	static  long total=0;
	static HashSet<String> s;
	static boolean bool[][];
	static int count=0;
	static  ArrayList<Pair> ar[][];
	static int maxx=0;
	static int maxy=0;
	public static void solve(){
	
		 in = new InputReader(System.in);
		 pw = new PrintWriter(System.out);
         int n=in.nextInt();
         int m=in.nextInt();
         g=new ArrayList[n+1];
         for(int i=0;i<=n;i++)
        	 g[i]=new ArrayList<Integer>();
         int cnt=0;
         for(int i=0;i<n;i++)
         {
        	 int Nums=in.nextInt();
        	 if(Nums!=0)
        		 cnt++;
        	 for(int j=0;j<Nums;j++)
        		 g[i].add(in.nextInt());
         }
         
         DSU d=new DSU(n);
      //   System.out.println(d.comp);
         for(int i=0;i<n;i++)
         {
        	 
        	 for(int j=i+1;j<n;j++)
        	 {
        		 for(int k=1;k<=m;k++)
        		 {
        			 if(g[i].contains(k)&&g[j].contains(k))
        			 {
        				// System.out.println("---");
        				 d.Merge(i, j);
        				 break;
        			 }
        		 }
        	 }
         }
         int ans=d.comp;
         if(cnt>0)
        	 ans--;
         System.out.println(ans);
     	}






	/*public static void dfs(int curr)
	{
		vis[curr]=true;
		int trees=0;
		for(int x:g[curr])
		{
			if(!vis[x]&&x!=1)
			{
			trees++;
			if(!s.contains(curr+" "+x))
				total+=cost[curr][x];
			dfs(x);
			}
	    }
		if(trees==0)
		{
			if(!s.contains(curr+" "+1))
				total+=cost[1][curr];
		}
	}
	public static void dfs1(int curr,int parent)
	{
	val[curr]=a[curr];
	for(int x:g[curr])
	{
	       if(x!=parent)
	       {
	    	   dfs1(x,curr);
	    	   val[curr]+=val[x];
	      }
	
	}
	}
	public static void dfs2(int curr,int parent)
	{
		f[curr]=val[curr];
		for(int x:g[curr])
		{
			if(x!=parent)
			{
				dfs2(x,curr);
				f[curr]+=f[x];
			}
		}
	}
	
	
	 
/*    public static void dfs2(int curr)
    {
    if(st[col[curr]].isEmpty())
    {
    ans[curr]=-1;	
    }
    else
    {
    	ans[curr]=st[col[curr]].peek();
    }
    st[col[curr]].push(curr);
    for(int x:g[curr])
    {
    	dfs2(x);
    }
    st[col[curr]].pop();
    	
    }
    
  
	public static void dfs1(int curr)
	{
		visited[curr]=true;
		for(int next:g[curr])
		{
			edje++;
			if(!visited[next])
				dfs1(next);
		}
	}
	
	public static void dfs(int curr,int prev)
		{
		val[curr]=1;
			for(int x:g[curr])
			{
				if(x!=prev)
				{
		            dfs(x,curr);
		            val[curr]+=val[x];
					
			    }
			}
		}*/


static class DSU 
{
public int rank[];
public int parent[];
public int n;
public int comp;
public DSU(int n)
{
	this.comp=n;
	this.n=n;
	makeSet();
}
private void makeSet() 
{
	rank=new int[n+1];
	parent=new int[n+1];
	
	for(int i=1;i<=n;i++)
	{
		rank[i]=0;
		parent[i]=i;
	}
}
public int find(int x)
{
	if(parent[x]!=x)
		parent[x]=find(parent[x]);
	return parent[x];
}
public void Merge(int x,int y)
{
	int xRoot=find(x);
	int yRoot=find(y);
	if(xRoot==yRoot)
		return;
	comp--;
	if(rank[xRoot]<rank[yRoot])
	{
		parent[xRoot]=yRoot;
	}
	else if(rank[yRoot]<rank[xRoot])
	{
		parent[yRoot]=xRoot;
	}
	else
	{
		parent[yRoot]=xRoot;
		rank[xRoot]++;
	}
}
}

		public static long power(long a,long b)
		{
			long result=1;
			while(b>0)
			{
				if(b%2==1)
					result*=a;
				a=a*a;
				b/=2;
			}
			return result;
		}
				public static long pow(long n,long p,long m)
	{
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	}
	static class Pair implements Comparable<Pair>{
	int day1;
		int day2;
		int val;
		Pair(int mr,int i){
	     	day1=mr;
	     	day2=i;
			
			
		}
		@Override
		public int compareTo(Pair o) {
		if(o.day1<this.day1)
		
			return 1;
			
			else 
				return -1;
			
			}
		
	}
	public static long gcd(long a, long b) {
		  if (b == 0) return a;
		  return gcd(b, a%b);
		}
	static class InputReader {
 
		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;
 
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
 
		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
 
		public   int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public String readString() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} 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 interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}
