#include<bits/stdc++.h>usingnamespace std;constint N =210, M =61000;bool d[N][N], st[N];int n, m;int match[N];boolfind(int u){for(int i =1; i <= n; i ++){//遍历所有点看哪个可以相连 if(d[u][i]&&!st[i]){
st[i]=true;int t = match[i];if(t ==0||find(t)){
match[i]= u;returntrue;}}}returnfalse;}intmain(){
cin>>n>>m;for(int i =0; i < m; i ++){int a, b;
cin>>a>>b;
d[a][b]=true;}for(int k =1; k <= n; k ++){for(int i =1; i <= n; i ++){for(int j =1; j <= n; j ++){
d[i][j]|= d[i][k]& d[k][j];//求传递闭包,就是将一条路上的一个点和后面所有能连起来的点相连 }}}int res =0;for(int i =1; i <= n; i ++){memset(st,0,sizeof st);if(find(i)) res ++;}
cout<<n - res <<endl;return0;}