import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { void run() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] deg = new int[n]; ArrayList[] g = new ArrayList[n]; for (int i = 0; i < g.length; ++i) g[i] = new ArrayList<>(); for (int i = 0; i < m; ++i) { int a = sc.nextInt(); int b = sc.nextInt(); --a; for (int j = 0; j < b; ++j) { int h = sc.nextInt(); --h; g[h].add(a); ++deg[a]; } } int INF = 99999; int ans = 0; out:for (int i = 0; i < n; ++i) { int mi = INF; for (int d : deg) mi = Math.min(mi, d); for (int j = 0; j < n; ++j) { if (deg[j] == mi) { if (deg[j] == 0) ++ans; else break out; deg[j] = INF; for (int dst : g[j]) --deg[dst]; } } } System.out.println(ans); } public static void main(String[] args) { new Main().run(); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }