import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList> outputs = new ArrayList<>(); ArrayList> inputs = new ArrayList<>(); for (int i = 0; i < n; i++) { outputs.add(new HashSet<>()); inputs.add(new HashSet<>()); } for (int i = 0; i < m; i++) { int to = sc.nextInt() - 1; int count = sc.nextInt(); for (int j = 0; j < count; j++) { int x = sc.nextInt() - 1; inputs.get(to).add(x); outputs.get(x).add(to); } } int ans = 0; ArrayDeque deq = new ArrayDeque<>(); for (int i = 0; i < n; i++) { if (inputs.get(i).size() == 0) { deq.add(i); ans++; } } while (deq.size() > 0) { int x = deq.poll(); for (int y : outputs.get(x)) { inputs.get(y).remove(x); if (inputs.get(y).size() == 0) { deq.add(y); ans++; } } } System.out.println(ans); } }