//第一题 dfs

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class test1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        Queue<Integer>[] queue = (LinkedList<Integer>[]) new LinkedList[num+1];
        for (int i = 1; i <= num; i++){
            queue[i] = new LinkedList<>();
        }
        for (int i = 1; i <= num; i++){
            int k = scan.nextInt();
            while (k != 0){
                queue[i].add(k);
                queue[k].add(i);
                k = scan.nextInt();
            }
        }
        boolean[] marked = new boolean[num+1]; //维护一个标记数组
        int count = 0;
        for (int i = 1; i <= num; i++){
            if (!marked[i]) {
                dfs(queue, marked, i);
                count++;
            }
        }
        System.out.println(count);
    }

    public static void dfs(Queue<Integer>[] queue, boolean[] marked, int v){
        marked[v] = true;
        for (int w : queue[v]){
            if (!marked[w]) {
                dfs(queue, marked, w);
            }
        }
    }
}