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.util.*;
public class learninglanguages{
    public static void main(String[] args) throws Exception
    {
        InputReader in=new InputReader(System.in);
        PrintWriter pw=new PrintWriter(System.out);
        int n=in.nextInt();
        int m=in.nextInt();
        disjointset ds=new disjointset();
        ds.createSet(m);
         int ans=0;
         long[] tt=new long[m];
        for(int i=0;i<n;i++)
        {
            int w=in.nextInt();
            if(w==0)
            {
                ans++;
            }
            else
            {
                int[] a=new int[w];
                for(int f=0;f<w;f++)
                {
                    a[f]=in.nextInt()-1;
                    tt[a[f]]++;
                }
                for(int f=1;f<w;f++)
                {
                    if(ds.findset(a[0])!=ds.findset(a[f]))
                    {
                        ds.mergeset(a[0], a[f]);
                    }
                }
            }
        }
        
        HashSet<Integer> hs=new HashSet<Integer>();
        for(int i=0;i<m;i++)
        {
            if(tt[i]!=0)
            {
                hs.add(ds.findset(i));
            }
        }
        if(hs.size()>=1)
        {
            ans+=(hs.size()-1);
        }
    
        pw.println(ans);
        pw.close();
    }
    
    
    
    
    
    
    
     static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int 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 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);
        }
    }

}

 class disjointset {
    static int[] parent;
    static int[] rank;
    static int connectedcomponent;
    public static void createSet(int n)
    {
        
        parent=new int[n];
        rank=new int[n];
        connectedcomponent=n;
        for(int i=0;i<n;i++)
        {
            parent[i]=i;
        }
        return;
    }
    public static int findset(int x)
    {
        if(x!=parent[x])
        {
            parent[x]=findset(parent[x]);
        }
        return parent[x];
    }
    public static void mergeset(int x,int y)
    {
        connectedcomponent--;
        int px=findset(x);
        int py=findset(y);
        if(rank[px]>rank[py])
        {
            parent[py]=px;
        }
        else
        {
            parent[px]=py;
        }
        if(rank[px]==rank[py])
        {
            rank[py]++;
        }
    }

}
