import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class SupportGuillaume {
    public static boolean bpm(boolean[][] mat, int u, boolean seen[], int matchR[], int N) {
        for(int v = 0; v < N; v++) {
            if (mat[u][v] && !seen[v]) {
                seen[v] = true; 
                if (matchR[v] < 0 || bpm(mat, matchR[v], seen, matchR, N)) {
                    matchR[v] = u;
                    return true;
                }
            }
        }
        return false;
    }
 
    public static int maxBPM(boolean[][] mat, int M, int N) {
        int matchR[] = new int[N];
        for(int i = 0; i < N; ++i) matchR[i] = -1;
 
        int result = 0; 
        for(int u = 0; u < M; u++) {
            boolean seen[] = new boolean[N] ;
            for(int i = 0; i < N; ++i) seen[i] = false;
            if(bpm(mat, u, seen, matchR, N)) result++;
        }

        return result;
    }

    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first_line = br.readLine().split(" ");
        int M = Integer.parseInt(first_line[0]), N = Integer.parseInt(first_line[1]);
        boolean[][] mat = new boolean[M][N];
        for(int i = 0; i < M; ++i) for(int j = 0; j < N; ++j) mat[i][j] = false;
        for(int i = 0; i < M; ++i) {
            int k = Integer.parseInt(br.readLine());
            String[] line = br.readLine().split(" ");
            for(int j = 0; j < line.length; ++j) {
                int col = Integer.parseInt(line[j]);
                mat[i][col - 1] = true;
            }
        }
        br.close();
        System.out.println(maxBPM(mat, M, N));
    }
}
