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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class LearningLanguages {
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    long L_INF = (1L << 60L);

    void solve() {
        int k, n = ni(), m = ni(), last, x;
        UnionFind uf = new UnionFind(m + 1);
        int zero = 0;
        boolean used[] = new boolean[m + 1];
        for (int i = 0; i < n; i++) {
            k = ni();
            if (k == 0) {
                zero++;
                continue;
            }
            last = ni();
            used[last] = true;
            for (int j = 1; j < k; j++) {
                x = ni();
                used[x] = true;
                uf.union(last, x);
                last = x;
            }
        }
        int indifferent = 0;
        for (int i = 1; i <= m; i++) {
            if (!used[i])
                indifferent++;
        }
//        System.out.println(uf.numOfComponents());
        if (indifferent == m)
            indifferent--;
        if (zero == 0) {
            pw.println(uf.numOfComponents() - 2 - indifferent);
        } else {
            pw.println(zero + uf.numOfComponents() - 2 - indifferent);
        }
    }

    class UnionFind {

        private int count; // num of components
        private int id[]; // id[i] = root of i
        private int rank[]; // rank[i] = size of subtree rooted at i (cant be more than 31)
        private int numNodes[];

        UnionFind(int n) {
            count = n;
            id = new int[n];
            rank = new int[n];
            numNodes = new int[n];
            int i;
            for (i = 0; i < n; i++) {
                id[i] = i; // each tree is its own root
                rank[i] = 0;
                numNodes[i] = 1;  // each tree has 1 node(itself) in the beginning
            }
        }

        /**
         * @return the root of the parameter p
         */
        int root(int p) {
            while (p != id[p]) {
                id[p] = id[id[p]]; // path compression
                p = id[p];
            }
            return p;
        }

        /**
         * @return true if a and b belong to same subtree
         */
        boolean find(int a, int b) {
            if (root(a) == root(b))
                return true;
            return false;
        }

        /**
         * union of subtree a with b according to rank
         */
        void union(int a, int b) {
            int root_a = root(a);
            int root_b = root(b);
            if (root_a == root_b)
                return;
            if (rank[root_a] > rank[root_b]) {
                id[root_b] = root_a;
                numNodes[root_a] += numNodes[root_b];
            } else if (rank[root_b] > rank[root_a]) {
                id[root_a] = root_b;
                numNodes[root_b] += numNodes[root_a];
            } else {
                id[root_a] = root_b;
                numNodes[root_b] += numNodes[root_a];
                rank[root_b]++;
            }

            count--;
        }

        /**
         * @return number of nodes in tree
         */
        int componentSize(int a) {
            int root_a = root(a);
            return numNodes[root_a];
        }

        /**
         * @return total number of components
         */
        int numOfComponents() {
            return count;
        }

    }


    void run() throws Exception {
//		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        is = System.in;
        pw = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
//        int t = ni();
//        while (t-- > 0)
        solve();
        pw.flush();
        tr(System.currentTimeMillis() - s + "ms");
    }

    public static void main(String[] args) throws Exception {
        new LearningLanguages().run();
    }

    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void tr(Object... o) {
        if (!oj) System.out.println(Arrays.deepToString(o));
    }
}