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

public class Codeforces {

    private static Print writer;

    private static Scan reader;

    static class Scan {
        private byte[] buf = new byte[1024];  //Buffer of Bytes
        private int index;
        private InputStream in;
        private int total;

        public Scan() throws IOException {
            in = System.in;
        }

        int next() throws IOException {  //Scan method used to scan buf
            if (total < 0)
                throw new InputMismatchException();
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0)
                    return -1;
            }
            return buf[index++];
        }

        int nextInt() throws IOException {
            int integer = 0;
            int n = next();
            while (isWhiteSpace(n))   //Removing startPointing whitespaces
                n = next();
            int neg = 1;
            if (n == '-') {           //If Negative Sign encounters
                neg = -1;
                n = next();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = next();
                } else throw new InputMismatchException();
            }
            return neg * integer;
        }

        long nextLong() throws IOException {
            long integer = 0;
            int n = next();
            while (isWhiteSpace(n))   //Removing startPointing whitespaces
                n = next();
            int neg = 1;
            if (n == '-') {           //If Negative Sign encounters
                neg = -1;
                n = next();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = next();
                } else throw new InputMismatchException();
            }
            return neg * integer;
        }

        String nextLine() throws IOException {
            StringBuilder sb = new StringBuilder();
            int n = next();
            while (isWhiteSpace(n)) n = next();
            while (!isNewLine(n)) {
                sb.append((char) n);
                n = next();
            }
            return sb.toString();
        }

        private boolean isNewLine(int n) {
            return n == '\n' || n == '\r' || n == -1;
        }

        private boolean isWhiteSpace(int n) {
            return n == ' ' || isNewLine(n) || n == '\t';
        }

        int[] nextIntArray(int n) throws Exception {
            if (n < 0) throw new Exception("Array size should be non negative");
            int[] array = new int[n];
            for (int i = 0; i < n; i++) array[i] = nextInt();
            return array;
        }

        List<Integer> nextIntList(int n) throws Exception {
            if (n < 0) throw new Exception("Array size should be non negative");
            List<Integer> array = new ArrayList<>(n);
            for (int i = 0; i < n; i++) array.add(nextInt());
            return array;
        }


        long[] nextLongArray(int n) throws Exception {
            if (n < 0) throw new Exception("Array size should be non negative");
            long[] array = new long[n];
            for (int i = 0; i < n; i++) array[i] = nextLong();
            return array;
        }
    }

    static class Print {
        private final BufferedWriter bw;


        Print() {
            bw = new BufferedWriter(new OutputStreamWriter(System.out));
        }

        <T> void print(T str) {
            try {
                bw.append(str.toString());
            } catch (IOException e) {
                System.out.println(e.toString());
            }
        }

        void println() {
            print("\n");
        }

        <T> void println(T str) {
            print(str + "\n");
        }

        void flush() throws IOException {
            bw.flush();
        }

        void close() {
            try {
                bw.close();
            } catch (IOException e) {
                System.out.println(e.toString());
            }
        }
    }

    public static void main (String[] args) throws Exception {
        long startPointTime = System.currentTimeMillis();
        reader = new Scan();
        writer = new Print();
        main2();
        long endTime = System.currentTimeMillis();
        float totalProgramTime = endTime - startPointTime;
        if (args.length > 0 && args[0].equals("time"))
            writer.println("Execution time is " + totalProgramTime + " (" + (totalProgramTime / 1000) + "s)");
        writer.close();
    }

    static class DisjointSet {
        int[] arr;
        DisjointSet(int size) {
            arr = new int[size + 1];
            makeSet();
        }
        void makeSet() {
            for (int i = 0; i < arr.length; i++) {
                arr[i] = i;
            }
        }
        void union(int i, int j) {
            if (i == j) return;
            j = find(j);
            i = find(i);
            arr[j] = arr[i];
        }
        int find(int i) {
            // System.out.println("Find i = " + i);
            while (arr[i] != i) {
                i = arr[i];
            }
            return arr[i];
        }
        public String toString() {
            return Arrays.toString(arr);
        }
    }

    static void main2 () throws Exception {
        int n = reader.nextInt();
        int m = reader.nextInt();
        Set<Integer>[] langs = new Set[1 + m];
        Set<Integer> idiots = new HashSet<>();
        for (int i = 0; i < langs.length; i++) {
            langs[i] = new HashSet<>();
        }
        for (int i = 0; i < n; i++) {
            int numLangKnown = reader.nextInt();
            if (numLangKnown == 0) idiots.add(i + 1);
            for (int j = 0; j < numLangKnown; j++) {
                langs[reader.nextInt()].add(i + 1);
            }
        }
        DisjointSet dsu = new DisjointSet(n);
        int root = -1; //should be set to some1 who knows atleast 1 lang
        // writer.println(Arrays.toString(langs));
        for (int i = 1; i < langs.length; i++) {
            if (!langs[i].isEmpty()) {
                //connect this language speakers in dsu
                int femp = -1;
                for (int emp : langs[i]) {
                    if (femp == -1) {
                        femp = emp;
                        if (root == -1) root = emp;
                    } else {
                        dsu.union(femp, emp);
                    }
                    // writer.println(dsu);
                }
            }
        }
        // writer.println("idiots " + idiots);
        // writer.println("root set at " + root);
        if (idiots.size() == n || root == -1) {
            writer.println(n);
        } else {
            //root is also set now
            int cost = 0;
            root = dsu.find(root);
            for (int i = 1; i <= n; i++) {
                if (idiots.contains(i)) {
                    // writer.println("person " + i + " is idiot");
                    cost++;
                    dsu.union(root, i);
                } else {
                    int parent = dsu.find(i);
                    if (parent != root) {
                    // writer.println("Parent of " + i + " is " + parent);
                        cost++;
                        dsu.union(root, parent);
                    }
                }
            }
            writer.println(cost);
        }
    }
}
