#include "bits/stdc++.h"

using namespace std;

int main() {
	int N; int M;
	while (~scanf("%d%d", &N, &M)) {
		vector<vector<int>> graph(N);
		vector<int> deg(N, 0);
		for (int i = 0; i < M; ++ i) {
			int g; int r;
			scanf("%d%d", &g, &r), -- g;
			for (int j = 0; j < r; ++ j) {
				int h;
				scanf("%d", &h), -- h;
				graph[h].push_back(g);
				++ deg[g];
			}
		}
		vector<int> que;
		for (int i = 0; i < N; ++ i)
			if (deg[i] == 0)
				que.push_back(i);
		for (int qh = 0; qh != que.size(); ++ qh) {
			int i = que[qh];
			for (int j : graph[i])
				if (-- deg[j] == 0)
					que.push_back(j);
		}
		int ans = (int)que.size();
		printf("%d\n", ans);
	}
}