#include using namespace std; const int N = 210, M = 30010; int n, m; int g[N][N], st[N]; int match[N]; int dfs(int x) { for (int i = 1; i <= n; i++) { if (g[x][i] && !st[i]) { st[i] = 1; int t = match[i]; if (t == -1 || dfs(t)) { match[i] = x; return 1; } } } return 0; } int main() { memset(match, -1, sizeof match); scanf("%d %d", &n, &m); while (m--) { int a, b; scanf("%d %d", &a, &b); g[a][b] = 1; } // floyd求传递闭包 for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) g[i][j] |= g[i][k] & g[k][j]; int res = 0; for (int i = 1; i <= n; i++) { memset(st, 0, sizeof st); if (dfs(i)) res++; } printf("%d\n", n - res); return 0; }