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.text.DecimalFormat;
import java.util.*;

public class CF_277A {
	public static void main(String[] args) {
		new CF_277A().run();
	}
	public void run(){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		DSU dsu = new DSU(m);
		boolean[] vis = new boolean[m];
		
		int zeroNum = 0;
		for(int i = 0;i<n;i++){
			int tmp = sc.nextInt();
			if(tmp == 0){
				zeroNum++;
				continue;
			}else if(tmp==1){
				int j = sc.nextInt();
				dsu.union(j-1, j-1);
				vis[j-1] = true;
			}else{
				int last = sc.nextInt();
				vis[last-1] = true;
				for(int j = 1;j<tmp;j++){
					int cur = sc.nextInt();
					vis[cur-1] = true;
					dsu.union(last-1, cur-1);
					last = cur;
				}
			}
		}
		
		int div = 0;
		for(int i = 0;i<m;i++){
			if(dsu.get(i)!=i)
				continue;
			if(!vis[i])
				continue;
			div++;
		}
		if(div == 0)
			out.println(zeroNum);
		else
			out.println(div+zeroNum-1);
		out.close();
	}
}
class FastScanner {
	public BufferedReader br;
	public StringTokenizer st;

	public FastScanner(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public boolean hasMoreTokens() {
		while (st == null || !st.hasMoreTokens()) {
			String line = null;
			try {
				line = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (line == null)
				return false;
			st = new StringTokenizer(line);
		}
		return true;
	}

	public String next() {
		if (!hasMoreTokens())
			return null;
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	//读一个int类型的数组
	public int[] readIntArray(int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = nextInt();
		}
		return array;
	}

	//读一个long数组
	public long[] readLongArray(int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = nextLong();
		}
		return array;
	}

	//读一个字符串数组
	public String[] readStringArray(int n) {
		String[] a = new String[n];
		for (int i = 0; i < n; i++) {
			a[i] = next();
		}
		return a;
	}

	//打乱一个数组，便于排序
	public void shuffleIntArray(int[] a) {
		Random rand = new Random();
		for (int i = 0; i < a.length; i++) {
			int x = rand.nextInt(i + 1); // 0~i
			int t = a[i];
			a[i] = a[x];
			a[x] = t;
		}
	}

	// 只适合比较小的数，太大的数会越界
	public long factorial(long n) {
		if (n == 0)
			return 1L;
		long res = 1;
		for (long i = 2; i <= n; i++) {
			res *= i;
		}
		return res;
	}

	// 只适合比较小的数，太大的数会越界
	public long combination(long mom, long son) {
		return factorial(mom) / (factorial(son) * factorial(mom - son));
	}

	//求最小公倍数
	public long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	//求最大公约数
	public long lcm(long a, long b) {
		return a * b / (gcd(a, b));
	}

	//格式化double类型的数
	public double format(String pattern, double d) {
		DecimalFormat df = new DecimalFormat(pattern);
		return Double.parseDouble(df.format(d));
	}

	//判断一个数是否是2的指数
	public boolean isPowerOfTwo(long v) {
		return (v & (v - 1)) == 0;
	}
}

class DSU {
	int[] p;

	public DSU(int n) {
		p = new int[n];
		clear();
	}

	public void clear() {
		for (int i = 0; i < p.length; i++) {
			p[i] = i;
		}
	}

	public int get(int x) {
		int y = x;
		while (y != p[y]) {
			y = p[y];
		}
		// 压缩
		while (x != p[x]) {
			int t = p[x];
			p[x] = y;
			x = t;
		}
		return y;
	}

	public boolean union(int a, int b) {
		a = get(a);
		b = get(b);
		p[a] = b;
		return a != b;
	}

}
